aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorPaul Eggert2013-07-12 10:30:48 -0700
committerPaul Eggert2013-07-12 10:30:48 -0700
commita773ed9ac83b950cb2a934e9d54e1880f44bd350 (patch)
treeaa859e605867e85ae4fdee5401deddb18e0a630a /src/process.c
parent7e649856bce883738622cc3533ad808c6ea1a73f (diff)
downloademacs-a773ed9ac83b950cb2a934e9d54e1880f44bd350.tar.gz
emacs-a773ed9ac83b950cb2a934e9d54e1880f44bd350.zip
Clean up errno reporting and fix some errno-reporting bugs.
* callproc.c (Fcall_process): * fileio.c (Fcopy_file, Finsert_file_contents, Fwrite_region): * process.c (create_process, Fmake_network_process): * unexaix.c (report_error): * unexcoff.c (report_error): Be more careful about reporting the errno of failed operations. The code previously reported the wrong errno sometimes. Also, prefer report_file_errno to setting errno + report_file_error. (Fcall_process): Look at openp return value rather than at path, as that's a bit faster and clearer when there's a numeric predicate. * fileio.c (report_file_errno): New function, with most of the old contents of report_file_error. (report_file_error): Use it. (Ffile_exists_p, Ffile_accessible_directory_p): Set errno to 0 when it is junk. * fileio.c (Faccess_file): * image.c (x_create_bitmap_from_file): Use faccessat rather than opening the file, to avoid the hassle of having a file descriptor open. * lisp.h (report_file_errno): New decl. * lread.c (Flocate_file_internal): File descriptor 0 is valid, too.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/process.c b/src/process.c
index 81be29082fc..4a38c47443a 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1616,6 +1616,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1616{ 1616{
1617 int inchannel, outchannel; 1617 int inchannel, outchannel;
1618 pid_t pid; 1618 pid_t pid;
1619 int vfork_errno;
1619 int sv[2]; 1620 int sv[2];
1620#ifndef WINDOWSNT 1621#ifndef WINDOWSNT
1621 int wait_child_setup[2]; 1622 int wait_child_setup[2];
@@ -1656,9 +1657,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1656 forkout = sv[1]; 1657 forkout = sv[1];
1657 if (pipe2 (sv, O_CLOEXEC) != 0) 1658 if (pipe2 (sv, O_CLOEXEC) != 0)
1658 { 1659 {
1660 int pipe_errno = errno;
1659 emacs_close (inchannel); 1661 emacs_close (inchannel);
1660 emacs_close (forkout); 1662 emacs_close (forkout);
1661 report_file_error ("Creating pipe", Qnil); 1663 report_file_errno ("Creating pipe", Qnil, pipe_errno);
1662 } 1664 }
1663 outchannel = sv[1]; 1665 outchannel = sv[1];
1664 forkin = sv[0]; 1666 forkin = sv[0];
@@ -1837,6 +1839,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1837 1839
1838 /* Back in the parent process. */ 1840 /* Back in the parent process. */
1839 1841
1842 vfork_errno = errno;
1840 XPROCESS (process)->pid = pid; 1843 XPROCESS (process)->pid = pid;
1841 if (pid >= 0) 1844 if (pid >= 0)
1842 XPROCESS (process)->alive = 1; 1845 XPROCESS (process)->alive = 1;
@@ -1851,6 +1854,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1851 emacs_close (forkin); 1854 emacs_close (forkin);
1852 if (forkin != forkout && forkout >= 0) 1855 if (forkin != forkout && forkout >= 0)
1853 emacs_close (forkout); 1856 emacs_close (forkout);
1857 report_file_errno ("Doing vfork", Qnil, vfork_errno);
1854 } 1858 }
1855 else 1859 else
1856 { 1860 {
@@ -1896,10 +1900,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1896 } 1900 }
1897#endif 1901#endif
1898 } 1902 }
1899
1900 /* Now generate the error if vfork failed. */
1901 if (pid < 0)
1902 report_file_error ("Doing vfork", Qnil);
1903} 1903}
1904 1904
1905void 1905void
@@ -3265,12 +3265,11 @@ usage: (make-network-process &rest ARGS) */)
3265 3265
3266 len = sizeof xerrno; 3266 len = sizeof xerrno;
3267 eassert (FD_ISSET (s, &fdset)); 3267 eassert (FD_ISSET (s, &fdset));
3268 if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) == -1) 3268 if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) < 0)
3269 report_file_error ("getsockopt failed", Qnil); 3269 report_file_error ("getsockopt failed", Qnil);
3270 if (xerrno) 3270 if (xerrno)
3271 errno = xerrno, report_file_error ("error during connect", Qnil); 3271 report_file_errno ("error during connect", Qnil, xerrno);
3272 else 3272 break;
3273 break;
3274 } 3273 }
3275#endif /* !WINDOWSNT */ 3274#endif /* !WINDOWSNT */
3276 3275
@@ -3354,11 +3353,10 @@ usage: (make-network-process &rest ARGS) */)
3354 if (is_non_blocking_client) 3353 if (is_non_blocking_client)
3355 return Qnil; 3354 return Qnil;
3356 3355
3357 errno = xerrno; 3356 report_file_errno ((is_server
3358 if (is_server) 3357 ? "make server process failed"
3359 report_file_error ("make server process failed", contact); 3358 : "make client process failed"),
3360 else 3359 contact, xerrno);
3361 report_file_error ("make client process failed", contact);
3362 } 3360 }
3363 3361
3364 inch = s; 3362 inch = s;