Skip to content

Commit

Permalink
Merge pull request #346 from olebole/unix-os
Browse files Browse the repository at this point in the history
NOIRLAB: several patches for libos.a
  • Loading branch information
olebole authored Jan 29, 2024
2 parents 1b00ad8 + a6ce956 commit de4e326
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion unix/os/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ alloc (
printf ("rw access to %s is denied\n", fp->f_name);
return (DV_DEVINUSE);
} else if (ruid && uid_executing(ruid)) {
if (ruid != getuid()) {
if ((uid_t)ruid != getuid()) {
if (!statonly)
printf ("%s already allocated to %s\n",
fp->f_name, (getpwuid(ruid))->pw_name);
Expand Down
4 changes: 2 additions & 2 deletions unix/os/getproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ uid_executing (int uid)
{
register struct dirent *direntp;
register DIR *dirp;
char fname[256];
char fname[320];
struct stat st;

dirp = opendir ("/proc");
while ((direntp = readdir(dirp)) != NULL) {
sprintf (fname, "/proc/%s", direntp->d_name);
if (stat (fname, &st))
return (0);
else if (st.st_uid == uid)
else if (st.st_uid == (uid_t) uid)
return (1);
}
(void) closedir (dirp);
Expand Down
4 changes: 2 additions & 2 deletions unix/os/zawset.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ZAWSET (
XINT *max_size /* max working set size, bytes */
)
{
int physmem=0, kb_page;
unsigned int physmem=0, kb_page;
int debug = (getenv(ENV_DEBUG) != NULL);
char *s;

Expand Down Expand Up @@ -113,7 +113,7 @@ ZAWSET (
setrlimit (RLIMIT_RSS, &rlp);
getrlimit (RLIMIT_RSS, &rlp);
*old_size = working_set_size;
*new_size = min(*best_size, min(max_wss,
*new_size = min((rlim_t)*best_size, min(max_wss,
rlp.rlim_cur == RLIM_INFINITY ? max_wss : rlp.rlim_cur));
}
if (debug)
Expand Down
12 changes: 7 additions & 5 deletions unix/os/zfinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,24 @@ ZFINFO (
static char owner[SZ_OWNERSTR+1];
struct passwd *pw;

if (osfile.st_uid == uid)
if (osfile.st_uid == (uid_t) uid) {
strncpy ((char *)fs->fi_owner, owner, SZ_OWNERSTR);
else {
fs->fi_owner[SZ_OWNERSTR-1] = '\0'; // ensure NULL term
} else {
setpwent();
pw = getpwuid (osfile.st_uid);
endpwent();

if (pw == NULL)
if (pw == NULL) {
sprintf ((char *)fs->fi_owner, "%d", osfile.st_uid);
else {
fs->fi_owner[SZ_OWNERSTR-1] = '\0'; // ensure NULL term
} else {
strncpy (owner, pw->pw_name, SZ_OWNERSTR);
strncpy ((char *)fs->fi_owner, owner, SZ_OWNERSTR);
fs->fi_owner[SZ_OWNERSTR-1] = '\0'; // ensure NULL term
uid = osfile.st_uid;
}
}
((char *)fs->fi_owner)[SZ_OWNERSTR] = EOS;
}

*status = XOK;
Expand Down
29 changes: 23 additions & 6 deletions unix/os/zfioks.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ static int ks_getword (char **ipp, char *obuf);
static void ks_whosts (struct irafhosts *hp, char *filename);
static char *ks_getpass (char *user, char *host);

static int rcmd_ (char **ahost, int inport, const char *locuser,
const char *remuser, const char *cmd, int *fd2p);

void pr_mask (char *str);

/* ZOPNKS -- Open a connected subprocess on a remote node. Parse the "server"
Expand Down Expand Up @@ -585,7 +588,7 @@ s_err: dbgmsgf ("S:in.irafksd fork complete, status=%d\n",
*/
hostp = host;
dbgmsgf ("C:rexec for host=%s, user=%s\n", host, username);
*chan = rcmd (&hostp, ks_rexecport(),
*chan = rcmd_ (&hostp, ks_rexecport(),
getlogin(), username, cmd, 0);

} else if (ks.protocol == C_REXEC_CALLBACK) {
Expand Down Expand Up @@ -622,7 +625,7 @@ s_err: dbgmsgf ("S:in.irafksd fork complete, status=%d\n",
hostp = host;
dbgmsgf ("rexec for host=%s, user=%s, using client port %d\n",
host, username, s_port);
ss = rcmd (&hostp, ks_rexecport(),
ss = rcmd_ (&hostp, ks_rexecport(),
getlogin(), username, callback_cmd, 0);

/* Wait for the server to call us back. */
Expand Down Expand Up @@ -769,7 +772,7 @@ r_err: dbgmsg ("rexec-callback connect failed\n");
dbgmsgf ("C:rexec %s@%s: %s\n", username, host, command);

hostp = host;
fd = rcmd (&hostp, ks_rexecport(),
fd = rcmd_ (&hostp, ks_rexecport(),
getlogin(), username, command, 0);

if (fd < 0) {
Expand Down Expand Up @@ -1235,7 +1238,7 @@ ks_puti (int fd, int ival)
static int
ks_geti (int fd)
{
register int value = 0;
int value = 0;
struct timeval timeout;
int stat, sig;
fd_set rfd;
Expand Down Expand Up @@ -1390,8 +1393,8 @@ ks_getlogin (
struct ksparam *ks /* networking parameters */
)
{
register struct irafhosts *hp;
register int i;
struct irafhosts *hp;
char userfile[SZ_PATHNAME];
char sysfile[SZ_PATHNAME];
char fname[SZ_PATHNAME];
Expand Down Expand Up @@ -1525,7 +1528,7 @@ query: if ((namep = ks_getpass (loginname, hostname)))

setjmp (jmpbuf);
value = time(NULL);
for (i=0; i < sizeof(jmpbuf)/sizeof(int); i++)
for (i=0; i < (int)(sizeof(jmpbuf)/sizeof(int)); i++)
value ^= ((int *)jmpbuf)[i];
value = (value << 13) / 1000 * 1000;
if (value < 0)
Expand Down Expand Up @@ -1958,3 +1961,17 @@ void pr_mask (char *str)
if (sigismember (&pending, SIGCHLD))
dbgmsg ("\tpr_mask: SIGCHLD pending\n");
}


/* RCMD_ -- Compat routine for deprecated system rcmd().
*/
static int
rcmd_(char **ahost, int inport, const char *locuser, const char *remuser,
const char *cmd, int *fd2p)
{
int res = 0;
#ifndef __APPLE__
res = rcmd (ahost, inport, locuser, remuser, cmd, fd2p);
#endif
return res;
}
5 changes: 3 additions & 2 deletions unix/os/zfiond.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ ZARDND (
FD_SET (np->datain, &readfds);

/* Determine maximum amount of data to be read. */
maxread = (np->flags & F_TEXT) ? *maxbytes/sizeof(XCHAR) : *maxbytes;
maxread = (np->flags & F_TEXT) ? (int)(*maxbytes/sizeof(XCHAR)) : (int)*maxbytes;

/* The following call to select shouldn't be necessary, but it
* appears that, due to the way we open a FIFO with O_NDELAY, read
Expand Down Expand Up @@ -806,8 +806,9 @@ nd_onsig (
/* If we get a SIGPIPE writing to a server the server has probably
* died. Make it look like there was an i/o error on the channel.
*/
if (sig == SIGPIPE && recursion++ == 0)
if (sig == SIGPIPE && recursion++ == 0) {
;
}

if (jmpset)
longjmp (jmpbuf, sig);
Expand Down
2 changes: 1 addition & 1 deletion unix/os/zmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ main (int argc, char *argv[])
*/
if (arg < argc) {
for (nchars=0; arg < argc; arg++) {
while (nchars + strlen(argv[arg]) > len_irafcmd) {
while ((int)(nchars + strlen(argv[arg])) > len_irafcmd) {
len_irafcmd += 1024;
irafcmd = (XCHAR *) realloc ((char *)irafcmd,
len_irafcmd * sizeof(XCHAR));
Expand Down

0 comments on commit de4e326

Please sign in to comment.