Changeset 2743
- Timestamp:
- Aug 14, 2007, 4:02:50 AM (15 years ago)
- Location:
- trunk/daemon
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/daemon.c
r2415 r2743 51 51 52 52 static void usage ( const char *, ... ); 53 static void readargs ( int, char **, int *, int *, char ** );53 static void readargs ( int, char **, int *, int *, char **, char ** ); 54 54 static int trylocksock ( const char * ); 55 55 static int getlock ( const char * ); … … 58 58 static void setupsigs ( struct event_base * ); 59 59 static void gotsig ( int, short, void * ); 60 static int savepid ( const char * ); 60 61 61 62 static int gl_lockfd = -1; … … 63 64 static int gl_sockfd = -1; 64 65 static char gl_sockpath[MAXPATHLEN] = ""; 66 static char gl_pidfile[MAXPATHLEN] = ""; 65 67 66 68 int … … 69 71 struct event_base * evbase; 70 72 int nofork, debug, sockfd; 71 char * sockpath ;73 char * sockpath, * pidfile; 72 74 73 75 setmyname( argv[0] ); 74 readargs( argc, argv, &nofork, &debug, &sockpath );76 readargs( argc, argv, &nofork, &debug, &sockpath, &pidfile ); 75 77 76 78 if( !nofork ) … … 84 86 } 85 87 88 if( 0 > savepid( pidfile ) ) 89 exit( 1 ); 86 90 atexit( exitcleanup ); 87 91 sockfd = trylocksock( sockpath ); … … 119 123 120 124 printf( 121 "usage: %s [-dfh] \n"125 "usage: %s [-dfh] [-p file] [-s file]\n" 122 126 "\n" 123 127 "Transmission %s http://transmission.m0k.org/\n" … … 127 131 " -f --foreground Run in the foreground and log to stderr\n" 128 132 " -h --help Display this message and exit\n" 133 " -p --pidfile <path> Save the process id in a file at <path>\n" 129 134 " -s --socket <path> Place the socket file at <path>\n" 130 135 "\n" … … 135 140 136 141 void 137 readargs( int argc, char ** argv, int * nofork, int * debug, char ** sock ) 138 { 139 char optstr[] = "dfhs:"; 142 readargs( int argc, char ** argv, int * nofork, int * debug, char ** sock, 143 char ** pidfile ) 144 { 145 char optstr[] = "dfhp:s:"; 140 146 struct option longopts[] = 141 147 { … … 143 149 { "foreground", no_argument, NULL, 'f' }, 144 150 { "help", no_argument, NULL, 'h' }, 151 { "pidfile", required_argument, NULL, 'p' }, 145 152 { "socket", required_argument, NULL, 's' }, 146 153 { NULL, 0, NULL, 0 } … … 148 155 int opt; 149 156 150 *nofork = 0; 151 *debug = 0; 152 *sock = NULL; 157 *nofork = 0; 158 *debug = 0; 159 *sock = NULL; 160 *pidfile = NULL; 153 161 154 162 while( 0 <= ( opt = getopt_long( argc, argv, optstr, longopts, NULL ) ) ) … … 161 169 case 'f': 162 170 *nofork = 1; 171 break; 172 case 'p': 173 *pidfile = optarg; 163 174 break; 164 175 case 's': … … 295 306 close( gl_lockfd ); 296 307 } 308 if( 0 != gl_pidfile[0] ) 309 { 310 unlink( gl_pidfile ); 311 } 297 312 } 298 313 … … 339 354 } 340 355 } 356 357 int 358 savepid( const char * file ) 359 { 360 FILE * pid; 361 362 pid = fopen( file, "wb" ); 363 if( NULL == pid ) 364 { 365 errnomsg( "failed to open pid file: %s", file ); 366 return -1; 367 } 368 369 if( 0 > fprintf( pid, "%d\n", (int) getpid() ) ) 370 { 371 errnomsg( "failed to write pid to file: %s", file ); 372 fclose( pid ); 373 unlink( file ); 374 return -1; 375 } 376 377 fclose( pid ); 378 strlcpy( gl_pidfile, file, sizeof gl_pidfile ); 379 380 return 0; 381 } -
trunk/daemon/transmission-daemon.1
r1924 r2743 33 33 .Nm 34 34 .Op Fl df 35 .Op Fl p Ar pid-file 35 36 .Op Fl s Ar socket-file 36 37 .Ek … … 50 51 .It Fl h Fl -help 51 52 Print command-line option descriptions. 53 .It Fl p Fl -pidfile Ar pid-file 54 Save the daemon's process ID in 55 .Ar pid-file . 56 .It Fl s Fl -socket Ar socket-file 57 Create the unix-domain socket file at 58 .Ar socket-file 59 instead of the platform-dependent default location. 52 60 .El 53 61 .Sh FILES
Note: See TracChangeset
for help on using the changeset viewer.