Translation update done using Pootle.
[gammu.git] / smsd / pidfile.c
blob335bec9df0193a8982447160263a455272333e4e
1 /**
2 * SMSD PID file handling
3 */
4 /* Copyright (c) 2009 Michal Cihar <michal@cihar.com> */
5 /* Licensend under GNU GPL 2 */
7 #include <stdio.h>
8 #include <signal.h>
9 #include <unistd.h>
10 #include <sys/types.h>
11 #include <stdlib.h>
13 #include "pidfile.h"
15 /**
16 * Check existing PID file if it points to existing application.
18 void check_pid(const char *pid_file)
20 FILE *file;
22 int other;
24 file = fopen(pid_file, "r");
25 if (file != NULL) {
26 if (fscanf(file, "%d", &other) == 1) {
27 if (kill(other, 0) == 0) {
28 fprintf(stderr,
29 "Another instance is running, please stop it first!\n");
30 exit(10);
31 } else {
32 fprintf(stderr, "Stale lock file, ignoring!\n");
34 } else {
35 fprintf(stderr, "Can not parse pidfile, ignoring!\n");
37 fclose(file);
41 /**
42 * Write a pid file.
44 void write_pid(const char *pid_file)
46 FILE *file;
48 file = fopen(pid_file, "w");
49 if (file != NULL) {
50 fprintf(file, "%d\n", getpid());
51 fclose(file);
52 } else {
53 fprintf(stderr, "Can not create pidfile!\n");
54 exit(1);
58 /* How should editor hadle tabs in this file? Add editor commands here.
59 * vim: noexpandtab sw=8 ts=8 sts=8: