On 2007-11-14, Marc Haber <[EMAIL PROTECTED]> wrote: > On Sun, 11 Nov 2007 11:47:49 +0000, Stephen Gran <[EMAIL PROTECTED]> > wrote: >>This one time, at band camp, Marc Haber said: >>> How many seconds until the "please make pidfile location configurable" >>> wishlist bug? >> >>Which is another, what, 5-10 lines of code? > > I do not feel able to write C code for string operations without > introducing a truckload of buffer overflows and off-by-one-errors.
Have you tried asking the author of ser2net if he is willing to add the functionality...? Anyway, here's a (compile-tested only) patch: --- ser2net-2.3/ser2net.c 2005-03-10 10:59:53.000000000 -0500 +++ ser2net-2.3.pidfile/ser2net.c 2007-11-14 12:56:07.885930455 -0500 @@ -41,6 +41,7 @@ static char *config_file = "/etc/ser2net.conf"; static char *config_port = NULL; +static char *pid_file = NULL; static int detach = 1; static int debug = 0; #ifdef USE_UUCP_LOCKING @@ -59,6 +60,7 @@ static char *help_string = " you must specify a -c after the last -C to have it read a config\n" " file, too." " -p <controller port> - Start a controller session on the given TCP port\n" +" -P <file> - set location of pid file\n" " -n - Don't detach from the controlling terminal\n" " -d - Don't detach and send debug I/O to standard output\n" #ifdef USE_UUCP_LOCKING @@ -83,6 +85,16 @@ arg_error(char *name) exit(1); } +void +make_pidfile(char *pidfile) +{ + FILE *fpidfile; + if (pidfile && (fpidfile = fopen(pidfile, "w"))) { + fprintf(fpidfile, "%d\n", getpid()); + fclose(fpidfile); + } +} + int main(int argc, char *argv[]) { @@ -147,6 +159,15 @@ main(int argc, char *argv[]) } config_port = argv[i]; break; + + case 'P': + i++; + if (i == argc) { + fprintf(stderr, "No pid file specified with -P\n"); + arg_error(argv[0]); + } + pid_file = argv[i]; + break; #ifdef USE_UUCP_LOCKING case 'u': @@ -206,6 +227,10 @@ main(int argc, char *argv[]) close(0); close(1); close(2); + + /* write pid file */ + make_pidfile(pid_file); + } else if (debug) { openlog("ser2net", LOG_PID | LOG_CONS | LOG_PERROR, LOG_DAEMON); } -- Robert Edmonds [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]