Skip to content
Snippets Groups Projects
Commit 77fd082f authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Resolve failure to touch files when non-owner on *nix

ftouch(), semfile_signal(), and JS file_utime() would fail to update a file's access/mod times with errno=EPERM if not run as the file's owner. From "man utime":

EPERM times is not NULL, the caller's effective UID does not match the owner of the file, and the caller is not privileged (Linux: does not have the CAP_FOWNER capability).

So use a NULL times parameter value when updating to a file's time stamp(s) to the current time.
parent 01cf3f87
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -3406,6 +3406,7 @@ js_utime(JSContext *cx, uintN argc, jsval *arglist)
int32 actime;
int32 modtime;
struct utimbuf ut;
struct utimbuf* tp = NULL;
jsrefcount rc;
BOOL ret;
......@@ -3421,11 +3422,8 @@ js_utime(JSContext *cx, uintN argc, jsval *arglist)
if(fname==NULL)
return(JS_TRUE);
/* use current time as default */
ut.actime = ut.modtime = time(NULL);
if(argc>1) {
actime=modtime=(int32_t)ut.actime;
actime=modtime=time32(NULL);
if(!JS_ValueToInt32(cx,argv[1],&actime)) {
free(fname);
return JS_FALSE;
......@@ -3438,10 +3436,11 @@ js_utime(JSContext *cx, uintN argc, jsval *arglist)
}
ut.actime=actime;
ut.modtime=modtime;
tp = &ut;
}
rc=JS_SUSPENDREQUEST(cx);
ret=utime(fname,&ut)==0;
ret=utime(fname, tp)==0;
free(fname);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
......
......@@ -98,11 +98,9 @@ FILE* fnopen(int* fd, const char* str, int access)
BOOL ftouch(const char* fname)
{
int file;
struct utimbuf ut;
/* update the time stamp */
ut.actime = ut.modtime = time(NULL);
if(utime(fname, &ut)==0)
if(utime(fname, NULL)==0)
return TRUE;
/* create the file */
......
......@@ -127,7 +127,6 @@ void semfile_list_free(str_list_t* filelist)
BOOL semfile_signal(const char* fname, const char* text)
{
int file;
struct utimbuf ut;
size_t textlen = 0;
ssize_t wrlen = 0;
#if !defined(NO_SOCKET_SUPPORT)
......@@ -143,6 +142,5 @@ BOOL semfile_signal(const char* fname, const char* text)
close(file);
/* update the time stamp */
ut.actime = ut.modtime = time(NULL);
return utime(fname, &ut)==0 && wrlen == (ssize_t)textlen;
return utime(fname, NULL)==0 && wrlen == (ssize_t)textlen;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment