-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
77 lines (68 loc) · 2.54 KB
/
main.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/***************************************************************************
* File: main.h
* Author: SkibbleBip
* Procedures:
* PID_Lock -Function that attempts to lock a PID file and returns the
* status of whether it was successful or not.
***************************************************************************/
#include <signal.h>
#include <syslog.h>
/*Handle signals and printing to syslog*/
#include <stdio.h>
#include <stdlib.h>
/*Standard IO and libraries*/
#include <errno.h>
#include <unistd.h>
#include <string.h>
#ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED
typedef unsigned char wavByte_t;
//define a byte as an unsigned character
const char* CAPS_FILE_DESC = "/tmp/caps_lock";
/*define the named FIFO that communicates server to client*/
/*Defines the key status for the inputted key and the status its in
(Currently only caps lock is in use)
*/
typedef enum { CAPS_ON,
NUM_ON,
SCROLL_ON,
CAPS_OFF,
NUM_OFF,
SCROLL_OFF
} Status_t;
#define TOGGLE_AXIS 3
/*when comparing if a key state has been set on or off, rather than doing
* "if else if else" for key states for playing audible notes, one just needs
* to check if state < TOGGLE_AXIS then play ding on, else play dong off*/
/***************************************************************************
* int PID_Lock(char* path, int *pidfile)
* Author: SkibbleBip
* Date: 05/28/2021
* Description: Function to attempt to lock a PID file and return if successful
* or not
*
* Parameters:
* path I/P char* The path of the PID file
* pidfile I/O int* The file descriptor of the PID file
* PID_Lock O/P int Return boolean status of if the process
* was successful
**************************************************************************/
int PID_Lock(char* path, int *pidfile)
{
*pidfile = open(path, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR | S_IWUSR);
/*Open the PID file*/
if(*pidfile < 0){
/*if failed to open, return with error*/
syslog(LOG_ERR, "Failed to open PID file %m");
return 0;
}
int lock = flock(*pidfile, LOCK_EX|LOCK_NB);
/*Lock the PID file*/
if(lock < 0){
/*if the lock is negative, it's already locked*/
syslog(LOG_ERR, "PID is locked, Application is already running\n");
return 0;
}
return 1;
}
#endif // MAIN_H_INCLUDED