root/src/plugins/pid.c @ 6

Revision 1, 0.9 kB (checked in by jinshiro, 17 years ago)
Line 
1
2#include <stdio.h>
3#include <string.h>
4
5#if !defined _WIN32 || defined MINGW
6        #include <unistd.h> // getpid(), unlink()
7#else
8        #include <windows.h>
9        #define getpid GetCurrentProcessId
10#endif
11
12#include "../common/plugin.h"
13
14PLUGIN_INFO = {
15        "ProcessId",
16        PLUGIN_ALL,
17        "1.0",
18        PLUGIN_VERSION,
19        "Logs the process ID"
20};
21
22PLUGIN_EVENTS_TABLE = {
23        { "pid_create", "Plugin_Init" },
24        { "pid_delete", "Plugin_Final" },
25        { NULL, NULL }
26};
27
28char pid_file[256];
29char *server_name;
30
31void pid_create ()
32{
33        FILE *fp;
34        int len;
35       
36        IMPORT_SYMBOL(server_name, 1);
37        len = strlen(server_name);
38        strcpy(pid_file, server_name);
39        if(len > 4 && pid_file[len - 4] == '.') {
40                pid_file[len - 4] = 0;
41        }
42        strcat(pid_file, ".pid");
43        fp = fopen(pid_file, "w");
44        if (fp) {
45                fprintf(fp, "%d", getpid());
46                fclose(fp);
47        }
48}
49
50void pid_delete ()
51{
52        unlink(pid_file);
53}
Note: See TracBrowser for help on using the browser.