Changeset 510


Ignore:
Timestamp:
07/12/11 13:06:33 (10 months ago)
Author:
jet
Message:

-- Add support for --pid option

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/man/crtmpserver.1

    r374 r510  
    5757.B \-\-gid=<gid> 
    5858Run the process with the specified group id. 
     59.TP 
     60.B \-\-pid=<file name> 
     61This option tells \fBcrtmpserver\fP to use the specified file as its pidfile. If the file exists, it will be over-written. 
     62.br 
     63Works only if \fB--daemon\fP option is specified. 
    5964.SH FILES 
    6065.TP 
  • trunk/sources/crtmpserver/src/crtmpserver.cpp

    r474 r510  
    6161void NormalizeCommandLine(string configFile); 
    6262bool ApplyUIDGID(); 
     63void WritePidFile(pid_t pid); 
    6364 
    6465RunningStatus gRs; 
     
    170171 
    171172                        if (pid > 0) { 
     173                                if (gRs.commandLine["arguments"].HasKey("--pid")) 
     174                                        WritePidFile(pid); 
    172175                                return false; 
    173176                        } 
     
    292295        cout << "    --gid=<gid>" << endl; 
    293296        cout << "      Run the process with the specified group id\n" << endl; 
     297        cout << "    --pid=<pid_file>" << endl; 
     298        cout << "      Create PID file."<< endl; 
     299        cout << "      Works only if --daemon option is specified\n"<< endl; 
    294300} 
    295301 
     
    342348} 
    343349 
     350void WritePidFile(pid_t pid) { 
     351        /*! 
     352         * Check if PID file exists 
     353         * If exists -> skip pid file creation 
     354         * if none -> write pid file 
     355         */ 
     356        string pidFile = gRs.commandLine["arguments"]["--pid"]; 
     357        struct stat sb; 
     358        if (stat(pidFile.c_str(), &sb) == 0) { 
     359                printf("pid file exists\n"); 
     360        } else if (errno != ENOENT) { 
     361                perror("stat"); 
     362                return; 
     363        } 
     364 
     365        FILE * f; 
     366        f = fopen(pidFile.c_str(), "w"); 
     367        if (f == NULL) { 
     368                perror("fopen"); 
     369                printf("warn: can not create PID file %s\n", pidFile.c_str()); 
     370                return; 
     371        } 
     372        fprintf(f, "%d", pid); 
     373        if (fclose(f) == -1) { 
     374                perror("fclose"); 
     375        } 
     376} 
     377 
    344378#ifdef COMPILE_STATIC 
    345379#ifdef HAS_APP_ADMIN 
Note: See TracChangeset for help on using the changeset viewer.