/[pengfork]/pengfork/src/modem/devlock.c
ViewVC logotype

Diff of /pengfork/src/modem/devlock.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by chupa, Mon Dec 2 15:57:12 2002 UTC revision 1.5 by chupa, Tue Dec 3 18:38:15 2002 UTC
# Line 69  device_lock (devicename) Line 69  device_lock (devicename)
69    if (fd != -1)    if (fd != -1)
70      {      {
71        /* We made a lock file... */        /* We made a lock file... */
72        sprintf (pid_string, "%10d\n", getpid ());        snprintf (pid_string, sizeof(pid_string), "%10d\n", getpid ());
73        write (fd, pid_string, strlen (pid_string));        write (fd, pid_string, strlen (pid_string));
74      }      }
75    else    else
# Line 78  device_lock (devicename) Line 78  device_lock (devicename)
78        sleep (1);                /* preventing race condition... */        sleep (1);                /* preventing race condition... */
79    
80        fd = open (filename, O_RDONLY);        fd = open (filename, O_RDONLY);
81        r = read (fd, pid_string, 15);        r = read (fd, pid_string, sizeof(pid_string) - 1);
82        pid_string[r] = '\0';        pid_string[r] = '\0';
83        pid = atoi (pid_string);        pid = atoi (pid_string);
84    
# Line 89  device_lock (devicename) Line 89  device_lock (devicename)
89            log (LOG_WARNING, gettext ("Removing stale lock file %s.\n"), filename);            log (LOG_WARNING, gettext ("Removing stale lock file %s.\n"), filename);
90            if (unlink (filename))            if (unlink (filename))
91              {              {
92                perror (filename);                log (LOG_ERR, gettext("Can't remove %s: %s (%d).\n"),
93                                    filename, strerror(errno), errno);
94                return 0;         /* cannot remove lockfile */                return 0;         /* cannot remove lockfile */
95              }              }
96            fd = open (filename, O_RDWR | O_EXCL | O_CREAT, 0644);            fd = open (filename, O_RDWR | O_EXCL | O_CREAT, 0644);
97            sprintf (pid_string, "%10d\n", getpid ());            snprintf (pid_string, sizeof(pid_string), "%10d\n", getpid ());
98            write (fd, pid_string, strlen (pid_string));            write (fd, pid_string, strlen (pid_string));
99          }          }
100        else        else

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26