Lines Matching +full:- +full:- +full:silent

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
52 static int acquire_lock(union lock_subject *subj, int flags, int silent);
63 static sig_atomic_t child = -1;
64 static int lockfd = -1;
82 if (strncmp(name, FDLOCK_PREFIX, sizeof(FDLOCK_PREFIX) - 1) != 0) in fdlock_implied()
86 name += sizeof(FDLOCK_PREFIX) - 1; in fdlock_implied()
111 bool silent, writepid; in main() local
113 silent = writepid = false; in main()
115 waitsec = -1; /* Infinite. */ in main()
116 while ((ch = getopt(argc, argv, "knpsTt:w")) != -1) { in main()
125 silent = true; in main()
148 argc -= optind; in main()
156 argc--; in main()
164 subj.subj_fd = -1; in main()
205 * If the "-k" option is not given, then we must not block when in main()
221 * When the "-k" option is used, the unlink race no longer in main()
226 lockfd = acquire_lock(&subj, flags | O_NONBLOCK, silent); in main()
227 while (lockfd == -1 && !timed_out && waitsec != 0) { in main()
229 lockfd = acquire_lock(&subj, flags, silent); in main()
233 silent); in main()
241 if (lockfd == -1) { /* We failed to acquire the lock. */ in main()
242 if (silent) in main()
255 if (atexit(cleanup) == -1) in main()
261 * an invalid pid (i.e., waited-on). If our setup between here and the in main()
277 if ((child = fork()) == -1) in main()
315 * on success, or -1 on failure.
318 acquire_lock(union lock_subject *subj, int flags, int silent) in acquire_lock() argument
323 assert(subj->subj_fd >= 0 && subj->subj_fd <= INT_MAX); in acquire_lock()
324 fd = (int)subj->subj_fd; in acquire_lock()
326 if (flock(fd, LOCK_EX | LOCK_NB) == -1) { in acquire_lock()
328 return (-1); in acquire_lock()
331 } else if ((fd = open(subj->subj_name, O_EXLOCK|flags, 0666)) == -1) { in acquire_lock()
333 return (-1); in acquire_lock()
335 if (!silent) in acquire_lock()
336 warn("%s", subj->subj_name); in acquire_lock()
339 err(EX_CANTCREAT, "cannot open %s", subj->subj_name); in acquire_lock()
358 * Signal handler for SIGTERM. Cleans up the lock file, then re-raises
369 if (raise(sig) == -1) in killed()
389 child = -1; in sigchld()
409 "usage: lockf [-knsw] [-t seconds] file command [arguments]\n" in usage()
410 " lockf [-s] [-t seconds] fd\n"); in usage()
423 if ((fd = open(name, O_RDONLY|O_EXLOCK, 0666)) == -1) { in wait_for_lock()