From: Lionel Sambuc Date: Thu, 29 Oct 2015 00:49:45 +0000 (+0100) Subject: Fix weird flock uses X-Git-Url: http://zhaoyanbai.com/repos/%22/xml/v3/net/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F23%2F3223%2F2;p=minix.git Fix weird flock uses Change-Id: If8593b8f8d6ef2f91a9ad9c3a0b9f0a02d52444d --- diff --git a/games/rogue/machdep.c b/games/rogue/machdep.c index e6d6292de..7c59eb0f6 100644 --- a/games/rogue/machdep.c +++ b/games/rogue/machdep.c @@ -443,7 +443,13 @@ md_lock(boolean l) if (l) { setegid(egid); +#if defined(__minix) + /* LSC: Minix flock implementation is a wrapper around fctl, which + * requires writeable fds for LOCK_EX to succeed. */ + if ((fd = open(_PATH_SCOREFILE, O_RDWR)) < 1) { +#else if ((fd = open(_PATH_SCOREFILE, O_RDONLY)) < 1) { +#endif /* defined(__minix) */ setegid(gid); messagef(0, "cannot lock score file"); return; diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c index 59100bf7d..47236a597 100644 --- a/usr.sbin/user/user.c +++ b/usr.sbin/user/user.c @@ -381,7 +381,13 @@ creategid(char *group, int gid, const char *name) warnx("Can't create group `%s': already exists", group); return 0; } +#if defined(__minix) + /* LSC: Minix flock implementation is a wrapper around fctl, which + * requires writeable fds for LOCK_EX to succeed. */ + if ((from = fopen(_PATH_GROUP, "r+")) == NULL) { +#else if ((from = fopen(_PATH_GROUP, "r")) == NULL) { +#endif /* defined(__minix) */ warn("Can't create group `%s': can't open `%s'", name, _PATH_GROUP); return 0; @@ -445,7 +451,13 @@ modify_gid(char *group, char *newent) int fd; int cc; +#if defined(__minix) + /* LSC: Minix flock implementation is a wrapper around fctl, which + * requires writeable fds for LOCK_EX to succeed. */ + if ((from = fopen(_PATH_GROUP, "r+")) == NULL) { +#else if ((from = fopen(_PATH_GROUP, "r")) == NULL) { +#endif /* defined(__minix) */ warn("Can't modify group `%s': can't open `%s'", group, _PATH_GROUP); return 0; @@ -568,7 +580,13 @@ append_group(char *user, int ngroups, const char **groups) } } } +#if defined(__minix) + /* LSC: Minix flock implementation is a wrapper around fctl, which + * requires writeable fds for LOCK_EX to succeed. */ + if ((from = fopen(_PATH_GROUP, "r+")) == NULL) { +#else if ((from = fopen(_PATH_GROUP, "r")) == NULL) { +#endif /* defined(__minix) */ warn("Can't append group(s) for `%s': can't open `%s'", user, _PATH_GROUP); return 0; @@ -1083,7 +1101,13 @@ adduser(char *login_name, user_t *up) login_name, up->u_class); } #endif +#if defined(__minix) + /* LSC: Minix flock implementation is a wrapper around fctl, which + * requires writeable fds for LOCK_EX to succeed. */ + if ((masterfd = open(_PATH_MASTERPASSWD, O_RDWR)) < 0) { +#else if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) { +#endif /* defined(__minix) */ err(EXIT_FAILURE, "Can't add user `%s': can't open `%s'", login_name, _PATH_MASTERPASSWD); } @@ -1316,7 +1340,13 @@ rm_user_from_groups(char *login_name) buf); return 0; } +#if defined(__minix) + /* LSC: Minix flock implementation is a wrapper around fctl, which + * requires writeable fds for LOCK_EX to succeed. */ + if ((from = fopen(_PATH_GROUP, "r+")) == NULL) { +#else if ((from = fopen(_PATH_GROUP, "r")) == NULL) { +#endif /* defined(__minix) */ warn("Can't remove user `%s' from `%s': can't open `%s'", login_name, _PATH_GROUP, _PATH_GROUP); return 0; @@ -1445,7 +1475,13 @@ moduser(char *login_name, char *newlogin, user_t *up, int allow_samba) /* keep dir name in case we need it for '-m' */ homedir = pwp->pw_dir; +#if defined(__minix) + /* LSC: Minix flock implementation is a wrapper around fctl, which + * requires writeable fds for LOCK_EX to succeed. */ + if ((masterfd = open(_PATH_MASTERPASSWD, O_RDWR)) < 0) { +#else if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) { +#endif /* defined(__minix) */ err(EXIT_FAILURE, "Can't modify user `%s': can't open `%s'", login_name, _PATH_MASTERPASSWD); }