mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-18 15:30:21 +00:00
Userland change corresponding to the change in kernel/userland communication
for NFS locking.
This commit is contained in:
parent
8b431c9576
commit
0cbf6231e8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=138431
@ -41,6 +41,7 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <paths.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -60,10 +61,6 @@
|
|||||||
|
|
||||||
#define DAEMON_USERNAME "daemon"
|
#define DAEMON_USERNAME "daemon"
|
||||||
|
|
||||||
#define nfslockdans(_v, _ansp) \
|
|
||||||
((_ansp)->la_vers = _v, \
|
|
||||||
nfsclnt(NFSCLNT_LOCKDANS, _ansp))
|
|
||||||
|
|
||||||
/* Lock request owner. */
|
/* Lock request owner. */
|
||||||
typedef struct __owner {
|
typedef struct __owner {
|
||||||
pid_t pid; /* Process ID. */
|
pid_t pid; /* Process ID. */
|
||||||
@ -79,6 +76,15 @@ int lock_request(LOCKD_MSG *);
|
|||||||
int test_request(LOCKD_MSG *);
|
int test_request(LOCKD_MSG *);
|
||||||
void show(LOCKD_MSG *);
|
void show(LOCKD_MSG *);
|
||||||
int unlock_request(LOCKD_MSG *);
|
int unlock_request(LOCKD_MSG *);
|
||||||
|
static int devfd;
|
||||||
|
|
||||||
|
static int
|
||||||
|
nfslockdans(int vers, struct lockd_ans *ansp)
|
||||||
|
{
|
||||||
|
|
||||||
|
ansp->la_vers = vers;
|
||||||
|
return (write(devfd, ansp, sizeof *ansp));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* will break because fifo needs to be repopened when EOF'd
|
* will break because fifo needs to be repopened when EOF'd
|
||||||
@ -104,7 +110,6 @@ void
|
|||||||
client_cleanup(void)
|
client_cleanup(void)
|
||||||
{
|
{
|
||||||
(void)lockd_seteuid(0);
|
(void)lockd_seteuid(0);
|
||||||
(void)unlink(_PATH_LCKFIFO);
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,21 +123,18 @@ client_request(void)
|
|||||||
{
|
{
|
||||||
LOCKD_MSG msg;
|
LOCKD_MSG msg;
|
||||||
fd_set rdset;
|
fd_set rdset;
|
||||||
int fd, nr, ret;
|
int nr, ret;
|
||||||
pid_t child;
|
pid_t child;
|
||||||
uid_t daemon_uid;
|
uid_t daemon_uid;
|
||||||
mode_t old_umask;
|
mode_t old_umask;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
/* Recreate the NLM fifo. */
|
/* Open the dev . */
|
||||||
(void)unlink(_PATH_LCKFIFO);
|
devfd = open(_PATH_DEV _PATH_NFSLCKDEV, O_RDWR | O_NONBLOCK);
|
||||||
old_umask = umask(S_IXGRP|S_IXOTH);
|
if (devfd < 0) {
|
||||||
if (mkfifo(_PATH_LCKFIFO, S_IWUSR | S_IRUSR)) {
|
syslog(LOG_ERR, "open: %s: %m", _PATH_NFSLCKDEV);
|
||||||
syslog(LOG_ERR, "mkfifo: %s: %m", _PATH_LCKFIFO);
|
goto err;
|
||||||
exit (1);
|
|
||||||
}
|
}
|
||||||
umask(old_umask);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a separate process, the client code is really a separate
|
* Create a separate process, the client code is really a separate
|
||||||
* daemon that shares a lot of code.
|
* daemon that shares a lot of code.
|
||||||
@ -154,11 +156,6 @@ client_request(void)
|
|||||||
owner.pid = getpid();
|
owner.pid = getpid();
|
||||||
(void)gethostname(hostname, sizeof(hostname) - 1);
|
(void)gethostname(hostname, sizeof(hostname) - 1);
|
||||||
|
|
||||||
/* Open the fifo for reading. */
|
|
||||||
if ((fd = open(_PATH_LCKFIFO, O_RDONLY | O_NONBLOCK)) == -1) {
|
|
||||||
syslog(LOG_ERR, "open: %s: %m", _PATH_LCKFIFO);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
pw = getpwnam(DAEMON_USERNAME);
|
pw = getpwnam(DAEMON_USERNAME);
|
||||||
if (pw == NULL) {
|
if (pw == NULL) {
|
||||||
syslog(LOG_ERR, "getpwnam: %s: %m", DAEMON_USERNAME);
|
syslog(LOG_ERR, "getpwnam: %s: %m", DAEMON_USERNAME);
|
||||||
@ -169,16 +166,8 @@ client_request(void)
|
|||||||
(void)lockd_seteuid(daemon_uid);
|
(void)lockd_seteuid(daemon_uid);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* Wait for contact... fifo's return EAGAIN when read with
|
|
||||||
* no data
|
|
||||||
*/
|
|
||||||
/* Set up the select. */
|
|
||||||
FD_ZERO(&rdset);
|
|
||||||
FD_SET(fd, &rdset);
|
|
||||||
(void)select(fd + 1, &rdset, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
/* Read the fixed length message. */
|
/* Read the fixed length message. */
|
||||||
if ((nr = read(fd, &msg, sizeof(msg))) == sizeof(msg)) {
|
if ((nr = read(devfd, &msg, sizeof(msg))) == sizeof(msg)) {
|
||||||
if (d_args)
|
if (d_args)
|
||||||
show(&msg);
|
show(&msg);
|
||||||
|
|
||||||
@ -221,19 +210,18 @@ client_request(void)
|
|||||||
}
|
}
|
||||||
} else if (nr == -1) {
|
} else if (nr == -1) {
|
||||||
if (errno != EAGAIN) {
|
if (errno != EAGAIN) {
|
||||||
syslog(LOG_ERR, "read: %s: %m", _PATH_LCKFIFO);
|
syslog(LOG_ERR, "read: %s: %m", _PATH_NFSLCKDEV);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
} else if (nr != 0) {
|
} else if (nr != 0) {
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR,
|
||||||
"%s: discard %d bytes", _PATH_LCKFIFO, nr);
|
"%s: discard %d bytes", _PATH_NFSLCKDEV, nr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reached only on error. */
|
/* Reached only on error. */
|
||||||
err:
|
err:
|
||||||
(void)lockd_seteuid(0);
|
(void)lockd_seteuid(0);
|
||||||
(void)unlink(_PATH_LCKFIFO);
|
|
||||||
_exit (1);
|
_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user