summaryrefslogtreecommitdiff
path: root/src/plugins/pid.c
blob: 62eb6878c42bafe50f3bc14c99d4f98da5a5680c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <string.h>
#ifndef _WIN32
	#include <unistd.h>
#else
	#define getpid GetCurrentProcessId
#endif
#ifdef MINGW
	#include <process.h>
	#include <io.h>
#endif
#include "../common/plugin.h"

PLUGIN_INFO = {
	"ProcessId",
	PLUGIN_ALL,
	"1.0",
	PLUGIN_VERSION,
	"Logs the process ID"
};

PLUGIN_EVENTS_TABLE = {
	{ "pid_create", "Plugin_Init" },
	{ "pid_delete", "Plugin_Final" },
	{ NULL, NULL }
};

char pid_file[256];
char *server_name;

void pid_create ()
{
	FILE *fp;
	int len;
	
	IMPORT_SYMBOL(server_name, 1);
	len = strlen(server_name);
	strcpy(pid_file, server_name);
	if(len > 4 && pid_file[len - 4] == '.') {
		pid_file[len - 4] = 0;
	}
	strcat(pid_file, ".pid");
	fp = fopen(pid_file, "w");
	if (fp) {
		fprintf(fp, "%d", getpid());
		fclose(fp);
	}
}

void pid_delete ()
{
	unlink(pid_file);
}