#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include "devfunc.h"
#include "../gsmstate.h"
Go to the source code of this file.
§ lock_path
#define lock_path "/var/lock/LCK.." |
§ max_buf_len
§ FindSerialSpeed()
int FindSerialSpeed |
( |
const char * |
buffer | ) |
|
Definition at line 367 of file devfunc.c.
Referenced by GSM_RegisterAllConnections().
369 switch (atoi(buffer)) {
372 case 110 :
return 110;
373 case 134 :
return 134;
374 case 150 :
return 150;
375 case 200 :
return 200;
376 case 300 :
return 300;
377 case 600 :
return 600;
378 case 1200 :
return 1200;
379 case 1800 :
return 1800;
380 case 2400 :
return 2400;
381 case 3600 :
return 3600;
382 case 4800 :
return 4800;
383 case 7200 :
return 7200;
384 case 9600 :
return 9600;
385 case 14400 :
return 14400;
386 case 19200 :
return 19200;
387 case 28800 :
return 28800;
388 case 38400 :
return 38400;
389 case 57600 :
return 57600;
390 case 115200 :
return 115200;
391 case 230400 :
return 230400;
392 case 460800 :
return 460800;
393 case 614400 :
return 614400;
394 case 921600 :
return 921600;
395 case 1228800 :
return 1228800;
396 case 2457600 :
return 2457600;
397 case 3000000 :
return 3000000;
398 case 6000000 :
return 6000000;
§ lock_device()
Definition at line 212 of file devfunc.c.
References ERR_DEVICELOCKED, ERR_DEVICENOPERMISSION, ERR_DEVICEOPENERROR, ERR_MOREMEMORY, ERR_NONE, ERR_UNKNOWN, ERR_WRITING_FILE, lock_device(), lock_path, max_buf_len, and smprintf().
Referenced by GSM_OpenConnection(), and lock_device().
214 char *lock_file = NULL;
226 aux = strrchr(port,
'/');
236 memset(buffer, 0,
sizeof(buffer));
237 lock_file = calloc(len + 1, 1);
239 smprintf(s,
"Out of memory error while locking device\n");
246 strcat(lock_file, aux);
250 if ((fd = open(lock_file, O_RDONLY)) >= 0) {
251 n = read(fd, buf,
sizeof(buf) - 1);
255 if (n == 4 && 4 ==
sizeof(
int) &&
257 isdigit((
int)buf[0]) &&
258 isdigit((
int)buf[1]) &&
259 isdigit((
int)buf[2]) &&
263 lseek(fd, 0, SEEK_SET);
266 n = read(fd, &pid,
sizeof(
int));
268 smprintf(s,
"Reading lock for second time failed\n");
275 sscanf(buf,
"%d", &pid);
281 if (pid > 0 && kill((pid_t)pid, 0) < 0 && errno == ESRCH) {
282 smprintf(s,
"Lockfile %s is stale. Overriding it..\n", lock_file);
283 if (unlink(lock_file) != 0) {
284 smprintf(s,
"Overriding failed, please check the permissions\n");
285 smprintf(s,
"Cannot lock device\n");
290 smprintf(s,
"Device already locked by PID %d.\n", pid);
297 fd = open(lock_file, O_CREAT | O_EXCL | O_WRONLY, 0644);
299 if (errno == EEXIST) {
300 smprintf(s,
"Device seems to be locked by unknown process\n");
302 }
else if (errno == EACCES) {
303 smprintf(s,
"Please check permission on lock directory\n");
305 }
else if (errno == ENOENT) {
306 smprintf(s,
"Cannot create lockfile %s. Please check for existence of path\n", lock_file);
309 smprintf(s,
"Unknown error with creating lockfile %s\n", lock_file);
314 sprintf(buffer,
"%10ld gammu\n", (
long)getpid());
315 wrotebytes = write(fd, buffer, strlen(buffer));
318 if (wrotebytes != strlen(buffer)) {
322 *lock_name = lock_file;
325 smprintf(s,
"Unable to read lockfile %s.\n", lock_file);
326 smprintf(s,
"Please check for reason and remove the lockfile by hand.\n");
327 smprintf(s,
"Cannot lock device\n");
int smprintf(GSM_StateMachine *s, const char *format,...)
§ unlock_device()