~ubuntu-branches/ubuntu/lucid/nfs-utils/lucid

« back to all changes in this revision

Viewing changes to utils/statd/statd.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2009-06-06 01:19:54 UTC
  • mto: (12.1.24 karmic)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090606011954-ojnwbumhfwgivicw
Tags: upstream-1.2.0
ImportĀ upstreamĀ versionĀ 1.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
static void 
89
89
sm_prog_1_wrapper (struct svc_req *rqstp, register SVCXPRT *transp)
90
90
{
 
91
        struct sockaddr_in *sin = nfs_getrpccaller_in(transp);
 
92
 
91
93
        /* remote host authorization check */
92
 
        if (!check_default("statd", svc_getcaller(transp),
93
 
                                 rqstp->rq_proc, SM_PROG)) {
 
94
        if (sin->sin_family == AF_INET &&
 
95
            !check_default("statd", sin, rqstp->rq_proc, SM_PROG)) {
94
96
                svcerr_auth (transp, AUTH_FAILED);
95
97
                return;
96
98
        }
177
179
                    pidfile, strerror(errno));
178
180
        fprintf(fp, "%d\n", getpid());
179
181
        pidfd = dup(fileno(fp));
180
 
        if (fclose(fp) < 0)
181
 
                note(N_WARNING, "Flushing pid file failed.\n");
 
182
        if (fclose(fp) < 0) {
 
183
                note(N_WARNING, "Flushing pid file failed: errno %d (%s)\n",
 
184
                        errno, strerror(errno));
 
185
        }
182
186
}
183
187
 
184
188
static void truncate_pidfile(void)
185
189
{
186
 
        if (pidfd >= 0)
187
 
                ftruncate(pidfd, 0);
 
190
        if (pidfd >= 0) {
 
191
                if (ftruncate(pidfd, 0) < 0) {
 
192
                        note(N_WARNING, "truncating pid file failed: errno %d (%s)\n",
 
193
                                errno, strerror(errno));
 
194
                }
 
195
        }
188
196
}
189
197
 
190
198
static void drop_privs(void)
205
213
        /* better chown the pid file before dropping, as if it
206
214
         * if over nfs we might loose access
207
215
         */
208
 
        if (pidfd >= 0)
209
 
                fchown(pidfd, st.st_uid, st.st_gid);
210
 
 
 
216
        if (pidfd >= 0) {
 
217
                if (fchown(pidfd, st.st_uid, st.st_gid) < 0) {
 
218
                        note(N_ERROR, "Unable to change owner of %s: %d (%s)",
 
219
                                        SM_DIR, strerror (errno));
 
220
                }
 
221
        }
211
222
        setgroups(0, NULL);
212
223
        if (setgid(st.st_gid) == -1
213
224
            || setuid(st.st_uid) == -1) {
493
504
        /* If we got this far, we have successfully started, so notify parent */
494
505
        if (pipefds[1] > 0) {
495
506
                status = 0;
496
 
                write(pipefds[1], &status, 1);
 
507
                if (write(pipefds[1], &status, 1) != 1) {
 
508
                        note(N_WARNING, "writing to parent pipe failed: errno %d (%s)\n",
 
509
                                errno, strerror(errno));
 
510
                }
497
511
                close(pipefds[1]);
498
512
                pipefds[1] = -1;
499
513
        }
532
546
load_state_number(void)
533
547
{
534
548
        int fd;
 
549
        const char *file = "/proc/sys/fs/nfs/nsm_local_state";
535
550
 
536
551
        if ((fd = open(SM_STAT_PATH, O_RDONLY)) == -1)
537
552
                return;
538
553
 
539
 
        read(fd, &MY_STATE, sizeof(MY_STATE));
 
554
        if (read(fd, &MY_STATE, sizeof(MY_STATE)) != sizeof(MY_STATE)) {
 
555
                note(N_WARNING, "Unable to read state from '%s': errno %d (%s)",
 
556
                                SM_STAT_PATH, errno, strerror(errno));
 
557
        }
540
558
        close(fd);
541
 
        fd = open("/proc/sys/fs/nfs/nsm_local_state",O_WRONLY);
 
559
        fd = open(file, O_WRONLY);
542
560
        if (fd >= 0) {
543
561
                char buf[20];
544
562
                snprintf(buf, sizeof(buf), "%d", MY_STATE);
545
 
                write(fd, buf, strlen(buf));
 
563
                if (write(fd, buf, strlen(buf)) != strlen(buf))
 
564
                        note(N_WARNING, "Writing to '%s' failed: errno %d (%s)",
 
565
                                file, errno, strerror(errno));
546
566
                close(fd);
547
567
        }
548
568