|
Lines 75-80
Link Here
|
| 75 |
#include <sys/wait.h> |
75 |
#include <sys/wait.h> |
| 76 |
#include <termios.h> |
76 |
#include <termios.h> |
| 77 |
#include <net/if.h> |
77 |
#include <net/if.h> |
|
|
78 |
#include <glob.h> |
| 78 |
|
79 |
|
| 79 |
#include "shvar.h" |
80 |
#include "shvar.h" |
| 80 |
#include "alloc.h" |
81 |
#include "alloc.h" |
|
Lines 116-121
Link Here
|
| 116 |
} |
117 |
} |
| 117 |
|
118 |
|
| 118 |
|
119 |
|
|
|
120 |
static int |
| 121 |
get_pppd_pid(char *device) { |
| 122 |
int i; |
| 123 |
glob_t globbuf; |
| 124 |
int ge = glob("/proc/*/cmdline", 0, NULL, &globbuf); |
| 125 |
if (!ge) { |
| 126 |
for (i = 0; i < globbuf.gl_pathc; ++i) { |
| 127 |
FILE *fcmdline; |
| 128 |
char cmdline[1024]; // hope this will be enough |
| 129 |
if (fcmdline = fopen(globbuf.gl_pathv[i], "r")) { |
| 130 |
int num_read; |
| 131 |
num_read = fread(cmdline, 1, 1024, fcmdline); |
| 132 |
if (num_read > 0 && !strcmp(cmdline, "/usr/sbin/pppd")) { |
| 133 |
int prev_linkname = 0; |
| 134 |
char *p = cmdline; |
| 135 |
while (*p && p - cmdline < 1024) { |
| 136 |
if (prev_linkname && !strcmp(p, device)) { |
| 137 |
int retval; |
| 138 |
globbuf.gl_pathv[i][strlen(globbuf.gl_pathv[i])-8] = 0; |
| 139 |
retval = atoi(globbuf.gl_pathv[i]+6); |
| 140 |
globfree(&globbuf); |
| 141 |
fclose(fcmdline); |
| 142 |
return retval; |
| 143 |
} |
| 144 |
prev_linkname = !strcmp(p, "linkname"); |
| 145 |
p += strlen(p) + 1; |
| 146 |
} |
| 147 |
} |
| 148 |
fclose(fcmdline); |
| 149 |
} |
| 150 |
} |
| 151 |
globfree(&globbuf); |
| 152 |
return 0; |
| 153 |
} |
| 154 |
else |
| 155 |
return -1; |
| 156 |
} |
| 119 |
|
157 |
|
| 120 |
static void |
158 |
static void |
| 121 |
detach(int now, int parentExitCode, char *device) { |
159 |
detach(int now, int parentExitCode, char *device) { |
|
Lines 550-555
Link Here
|
| 550 |
if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; } |
588 |
if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; } |
| 551 |
physicalDevice = pppLogicalToPhysical(&pppdPid, real_device); |
589 |
physicalDevice = pppLogicalToPhysical(&pppdPid, real_device); |
| 552 |
if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; } |
590 |
if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; } |
|
|
591 |
if (!pppdPid && get_pppd_pid(device)) |
| 592 |
{ |
| 593 |
// We suspect that pppd is running, but haven't created |
| 594 |
// .pid file yet. So we'll wait for 10 seconds, checking |
| 595 |
// for .pid file every 10 milliseconds. |
| 596 |
int i; |
| 597 |
for (i = 0; i < 1000 && !pppdPid && get_pppd_pid(device) !=0 ; ++i) |
| 598 |
{ |
| 599 |
usleep(10000); |
| 600 |
physicalDevice = pppLogicalToPhysical(&pppdPid, real_device); |
| 601 |
if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; } |
| 602 |
} |
| 603 |
sleep(2); // Else pppd may hangup, seems there's a bug in it |
| 604 |
} |
| 553 |
if (!pppdPid) cleanExit(35); |
605 |
if (!pppdPid) cleanExit(35); |
| 554 |
kill(pppdPid, sendsig); |
606 |
kill(pppdPid, sendsig); |
| 555 |
if (sendsig == SIGKILL) { |
607 |
if (sendsig == SIGKILL) { |