- char buf[80];
- char *p;
-
- if (!no_act) {
- int flags;
- struct flock lock;
- const int state_fd = fileno(state_fp);
-
- flags = fcntl(state_fd, F_GETFD);
- if ((flags < 0) || (fcntl(state_fd, F_SETFD, flags | FD_CLOEXEC) < 0)) {
- perror_msg_and_die("failed to set FD_CLOEXEC on statefile %s", statefile);
- }
-
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 0;
-
- if (fcntl(state_fd, F_SETLKW, &lock) < 0) {
- perror_msg_and_die("failed to lock statefile %s", statefile);
- }
- }
-
- rewind(state_fp);
- while ((p = fgets(buf, sizeof buf, state_fp)) != NULL) {
- char *pch;
-
- pch = buf + xstrlen(buf) - 1;
- while (pch > buf && isspace(*pch)) {
- pch--;
- }
- *(pch + 1) = '\0';
-
- pch = buf;
- while (isspace(*pch)) {
- pch++;
- }
-
- add_to_state(&state, &n_state, &max_state, xstrdup(pch));
+ char *start;
+ while ((start = get_line_from_file(state_fp)) != NULL) {
+ char *end_ptr;
+ /* We should only need to check for a single character */
+ end_ptr = start + strcspn(start, " \t\n");
+ *end_ptr = '\0';
+ state_list = llist_add_to(state_list, start);