bmsd/lock.c

changeset 747
b6fbe6821468
parent 746
44d929ff268e
equal deleted inserted replaced
746:44d929ff268e 747:b6fbe6821468
41 lockfile = calloc(PATH_MAX, sizeof(char)); 41 lockfile = calloc(PATH_MAX, sizeof(char));
42 42
43 snprintf(tempfile, PATH_MAX, "%s/run/%s.tmp", Private_Path, name); 43 snprintf(tempfile, PATH_MAX, "%s/run/%s.tmp", Private_Path, name);
44 snprintf(lockfile, PATH_MAX, "%s/run/%s.pid", Private_Path, name); 44 snprintf(lockfile, PATH_MAX, "%s/run/%s.pid", Private_Path, name);
45 45
46 if (mkdirs(tempfile, 0755) == FALSE) { 46 if (mkdirs(tempfile, 0755) == false) {
47 syslog(LOG_NOTICE, "Can't create path `%s': %s", tempfile, strerror(errno)); 47 syslog(LOG_NOTICE, "Can't create path `%s': %s", tempfile, strerror(errno));
48 free(tempfile); 48 free(tempfile);
49 free(lockfile); 49 free(lockfile);
50 return 1; 50 return 1;
51 } 51 }
57 return 1; 57 return 1;
58 } 58 }
59 fprintf(fp, "%u\n", getpid()); 59 fprintf(fp, "%u\n", getpid());
60 fclose(fp); 60 fclose(fp);
61 61
62 while (TRUE) { 62 while (true) {
63 if (link(tempfile, lockfile) == 0) { 63 if (link(tempfile, lockfile) == 0) {
64 unlink(tempfile); 64 unlink(tempfile);
65 free(tempfile); 65 free(tempfile);
66 free(lockfile); 66 free(lockfile);
67 return 0; 67 return 0;

mercurial