3 * Copyright (C) 2002 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /*****************************************************************************
22 * Set of definition for service routines
26 * $Id: Gapil.h,v 1.12 2003/08/16 18:30:21 piccardi Exp $
28 *****************************************************************************/
29 #include <sys/sem.h> /* IPC semaphore declarations */
30 #include <sys/shm.h> /* IPC shared memory declarations */
31 #include <sys/types.h>
33 #include <unistd.h> /* unix standard functions */
34 #include <fcntl.h> /* file control (lock) functions */
35 #include <signal.h> /* signal handling declarations */
36 #include <dirent.h> /* directory scan functions */
37 #include <stdio.h> /* include standard I/O library */
39 * Definition of semun struct; used to implement a MutexXXXX API To
40 * create a Mutex use an underlaying semaphore and init it; we put
41 * here all the needed data structures
43 /* use this definition, get from the man pages */
44 #if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
45 /* union semun is defined by including <sys/sem.h> */
47 /* according to X/OPEN we have to define it ourselves */
49 int val; /* value for SETVAL */
50 struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
51 unsigned short int *array; /* array for GETALL, SETALL */
52 struct seminfo *__buf; /* buffer for IPC_INFO */
56 * Mutex handling Functions
58 /* Function MutexCreate: create a mutex. See Mutex.c */
59 int MutexCreate(key_t ipc_key);
60 /* Function MutexFind: get the mutex ID given fomr IPC key. See Mutex.c */
61 int MutexFind(key_t ipc_key);
62 /* Function MutexRead: read the current value of the mutex. See Mutex.c */
63 int MutexRead(int sem_id);
64 /* Function MutexLock: to lock a mutex/semaphore. See Mutex.c */
65 int MutexLock(int sem_id);
66 /* Function MutexUnlock: to unlock a mutex/semaphore. See Mutex.c */
67 int MutexUnlock(int sem_id);
68 /* Function MutexRemove: remove the mutex/semphore. See Mutex.c */
69 int MutexRemove(int sem_id);
70 /* Function CreateMutex: create a mutex (using file locking). See Mutex.c */
71 int CreateMutex(const char *path_name);
72 /* Function UnlockMutex: find a mutex (using file locking). See Mutex.c */
73 int FindMutex(const char *path_name);
74 /* Function LockMutex: acquire a mutex (using file locking). See Mutex.c */
75 int LockMutex(int fd);
76 /* Function UnlockMutex: release a mutex (using file locking). See Mutex.c */
77 int UnlockMutex(int fd);
78 /* Function ReadMutex: read a mutex (using file locking). See Mutex.c */
79 int ReadMutex(int fd);
80 /* Function RemoveMutex: remove a mutex (using file locking). See Mutex.c */
81 int RemoveMutex(const char *path_name);
83 * Lock files function: to create and destroy lock files
85 /* Function LockFile: create a lock file. See FileLock.c */
86 int LockFile(const char* path_name);
87 /* Function UnlockFile: remove a lock file. See FileLock.c */
88 int UnlockFile(const char* path_name);
90 * Signal Handling Functions
92 typedef void SigFunc(int);
93 /* Function Signal: Initialize a signal handler. See SigHand.c */
94 SigFunc * Signal(int signo, SigFunc *func);
95 /* Function SignalRestart: restart system calls. See SigHand.c */
96 SigFunc * SignalRestart(int signo, SigFunc *func);
97 /* Function HandSigCHLD: to handle SIGCHILD. See SigHand.c */
98 void HandSigCHLD(int sig);
100 * Socket/Files service functions
102 /* Function FullRead: to read from a socket. See FullRead.c */
103 ssize_t FullRead(int fd, void *buf, size_t count);
104 /* Function FullWrite: to read from a socket. See FullWrite.c */
105 ssize_t FullWrite(int fd, const void *buf, size_t count);
106 /* Function full_fread: to read from a standard file. See full_fread.c */
107 size_t full_fread(FILE *file, void *buf, size_t count);
108 /* Function full_fwrite: to write from a standard file. See full_fwrite.c */
109 size_t full_fwrite(FILE *file, void *buf, size_t count);
113 /* Function dir_scan: simple scan for a directory. See dir_scan.c */
114 int dir_scan(char * dirname, int(*compute)(struct dirent *));
115 /* Function InitFile: secure create of a file with initial content */
116 ssize_t InitFile(int dirfd, const char *file, const char *buf, size_t size);
117 /* Function full_fread: to read from a standard file. See full_fread.c */
119 * Shared memory handling functions. See SharedMem.c
121 /* Function ShmCreate: create a SysV shared memory */
122 void * ShmCreate(key_t ipc_key, int shm_size, int perm, int fill);
123 /* Function ShmFind: find an existing SysV shared memory */
124 void * ShmFind(key_t ipc_key, int shm_size);
125 /* Function ShmRemove: remove a SysV shared memory */
126 int ShmRemove(key_t ipc_key, void * shm_ptr);
127 /* Function CreateShm: create a POSIX shared memory */
128 void * CreateShm(char * shm_name, off_t shm_size, int perm, int fill);
129 /* Function FindShm: find an existing POSIX shared memory */
130 void * FindShm(char * shm_name, off_t shm_size);
131 /* Function RemoveShm: remove a POSIX shared memory */
132 int RemoveShm(char * shm_name);
134 * Socket creation functions. See corresponding .c
136 int sockconn(char *host, char *serv, int prot, int type);
137 int sockbind(char *host, char *serv, int prot, int type);
138 int sockbindopt(char *host, char *serv, int prot, int type, int reuse);
141 * General purpose functions. See corresponding .c
144 int is_closing(int sock);