summaryrefslogtreecommitdiffstats
path: root/daemon/file.c
Commit message (Collapse)AuthorAgeFilesLines
* Use O_CLOEXEC / SOCK_CLOEXEC for almost all file descriptors.Richard W.M. Jones2012-03-141-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | The presumption is that all file descriptors should be created with the close-on-exec flag set. The only exception are file descriptors that we want passed through to exec'd subprocesses (mainly pipes and stdin/stdout/stderr). For open calls, we pass O_CLOEXEC as an extra flag, eg: fd = open ("foo", O_RDONLY|O_CLOEXEC); This is a Linux-ism, but using a macro we can easily make it portable. For sockets, similarly: sock = socket (..., SOCK_STREAM|SOCK_CLOEXEC, ...); For accepted sockets, we use the Linux accept4 system call which allows flags to be supplied, but we use the Gnulib 'accept4' module to make this portable. For dup, dup2, we use the Linux dup3 system call, and the Gnulib modules 'dup3' and 'cloexec'.
* Replace 'int' with 'size_t' passim.Richard W.M. Jones2012-03-131-2/+3
| | | | | Analyze all uses of 'int' in the code, and replace with 'size_t' where appropriate.
* daemon: Implement a growable strings buffer type.Richard W.M. Jones2012-03-131-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | Previously a lot of daemon code used three variables (a string list, 'int size' and 'int alloc') to track growable strings buffers. This commit implements a simple struct containing the same variables, but using size_t instead of int: struct stringsbuf { char **argv; size_t size; size_t alloc; }; Use it like this: DECLARE_STRINGSBUF (ret); //... if (add_string (&ret, str) == -1) return NULL; //... if (end_stringsbuf (&ret) == -1) return NULL; return ret.argv;
* comment: Note time-of-check to time-of-use race found by Coverity.Richard W.M. Jones2012-03-081-0/+6
|
* Revert "daemon: Run udev_settle after pwrite-device finishes."Richard W.M. Jones2012-02-061-15/+3
| | | | This reverts commit a9c8123c72db47bcab8dd738e8d5256a9ae87f11.
* daemon: Run udev_settle after pwrite-device finishes.Richard W.M. Jones2012-01-191-3/+15
| | | | | | | When you call close on any block device, udev kicks off a rule which runs blkid to reexamine the device. We need to wait for this rule to finish running since it holds the device open and can cause other operations to fail, notably BLKRRPART.
* daemon: pwrite/pread: Don't double close on error path.Richard W.M. Jones2012-01-191-2/+0
| | | | | In Linux, close (fd) closes the file descriptor even if it returns an error.
* Tempus fugit.Richard W.M. Jones2012-01-181-1/+1
| | | | Update all copyright dates to 2012.
* Update FSF address.Matthew Booth2011-11-081-1/+1
|
* New API: write-appendRichard W.M. Jones2011-07-141-1/+29
| | | | Append content to the end of a file.
* daemon: Don't use ../src path to include generator_protocol.hRichard W.M. Jones2010-11-031-1/+1
| | | | | This file is already hard-linked into the current directory, so the relative path is not required.
* New API: pread-device, partial read for devices.Richard W.M. Jones2010-09-271-15/+38
|
* pread: Check count and offset parameters are not negative.Richard W.M. Jones2010-09-271-0/+10
|
* New API: pwrite-deviceRichard W.M. Jones2010-09-261-9/+35
| | | | | This is the same as the existing 'pwrite' API call, but allows you to write to a device.
* pwrite: Check offset is not negative.Richard W.M. Jones2010-09-261-0/+5
|
* daemon: Move 'exists', 'is-file' and 'is-dir' to separate file.Richard Jones2010-09-091-34/+0
| | | | This commit is just code movement.
* file: Fix file command on /dev/VG/LV paths (RHBZ#582484).Richard Jones2010-06-081-1/+6
| | | | | | | | | | | | | Previous commit 4df593496e116dfb635731c058b7627e81fc179c broke the "file" command on logical volume paths, since these are symbolic links. We *should* follow these (only). This inadvertantly broke virt-inspector too, which indicates that we need more regression testing in this area. Since carrying whole Fedora images around could make the distribution even larger than now, I'm not sure at the moment how to do this. Thanks to Matt Booth for diagnosing this bug.
* file: Restrict to regular files (RHBZ#582484).Richard Jones2010-06-041-11/+35
| | | | | | | | | | | | | | | | | | | | | | The file call can hang if called on char devices (because we are using the file -s option). This is hard to solve cleanly without adding another file API. However this restricts file to regular files, unless called explicitly with a /dev/ path. For non-regular files, it will now return a string like "directory". There is a small semantic change for symbolic links. Previously it would not have worked at all on absolute links (or rather, the results would have been undefined). It would have treated relative symlinks to regular files as the regular file itself. Now it will return the string "symbolic link" in both cases. This commit also makes the API safe when called on untrusted filesystems. Previously a filesystem might have been set up so that (eg) /etc/redhat-release was a char device, which would have caused virt-inspector and virt-v2v to hang. Now it will not hang.
* touch: Restrict touch to regular files only (RHBZ#582484).Richard Jones2010-06-041-0/+20
|
* daemon: Rearrange code in 'file' command.Richard Jones2010-06-041-16/+15
| | | | | | | | path = path to access file (/sysroot/.. or /dev/..) display_path = original path, saved so we can display it buf = optional buffer which is freed along return codepaths There should be no change to the semantics of the code.
* daemon: write-file: Check range of size parameter (RHBZ#597135).Richard Jones2010-06-021-1/+22
| | | | This also adds a regression test.
* New API: Implement pwrite system call (partial fix for RHBZ#592883).Richard Jones2010-05-201-0/+31
|
* New API: write for creating files with fixed content (RHBZ#501889).Richard Jones2010-05-201-0/+28
| | | | | | | | | | | | | The guestfs_write call can be used to create small files with arbitrary 8 bit content, including \0 bytes. This replaces and deprecates write-file, which cannot be modified to use BufferIn because of an unfortunate choice in the ABI: the size parameter to write-file, if zero, means that the daemon tries to calculate the length of the buffer using strlen. However this fails if we pass a zero-length buffer using BufferIn because then the daemon tries to do strlen on a (really) zero length buffer, not even containing a terminating \0 character, thus segfaulting.
* daemon: Fix read-file so it fails gracefully for large files (RHBZ#589039).Richard Jones2010-05-071-4/+10
| | | | | | | | | | | | | | | | Pengzhen Cao noticed that read-file would fail for files larger than the protocol size; this is *not* the bug. However it would also lose protocol synchronization after this. The reason was that functions which return RBufferOut in the generator must not 'touch' the *size_r parameter along error return paths. I fixed read-file and initrd-cat, and I checked that pread was doing the right thing. This also adds regression tests for read-file with various categories of large file.
* Improved checking, documentation of modes (RHBZ#582901, RHBZ#582929).Richard Jones2010-04-171-0/+5
| | | | | | | | | | | chmod: Disallow negative mode, document mode affected by umask. mkdir-mode: Disallow negative mode, document that filesystems may interpret the mode in different ways. mknod: Disallow negative mode, document mode affected by umask. umask: Check the range of umask mask value carefully.
* daemon: Don't need to prefix error messages with the command name.Richard Jones2010-02-121-12/+12
| | | | | | | | | | | | | | | | | | | | The RPC stubs already prefix the command name to error messages. The daemon doesn't have to do this. As a (small) benefit this also makes the daemon slightly smaller. Code in the daemon such as: if (argv[0] == NULL) { reply_with_error ("passed an empty list"); return NULL; } now results in error messages like this: ><fs> command "" libguestfs: error: command: passed an empty list (whereas previously you would have seen ..command: command:..)
* Add 'filesize' call.Richard Jones2010-01-251-0/+18
| | | | | Returns the size of a file. You can already do this with 'stat', but this call is good for scripting.
* daemon: Use gnulib futimens module.Richard Jones2009-11-251-4/+0
| | | | | | | | | Instead of checking for futimens support and falling back (incorrectly in one case) to using futimes, use gnulib's module. However the gnulib module does not yet support Win32, so this change is only really useful on platforms like RHEL 5.
* use STREQ, not strcmp: part 1Jim Meyering2009-11-091-2/+2
| | | | | git grep -l 'strcmp *([^=]*== *0'|xargs \ perl -pi -e 's/\bstrcmp( *\(.*?\)) *== *0/STREQ$1/g'
* change strncmp() == 0 to STREQLEN()Jim Meyering2009-11-091-1/+1
| | | | | git grep -l 'strncmp *([^=]*== *0'|xargs \ perl -pi -e 's/\bstrncmp( *\(.*?\)) *== *0\b/STREQLEN$1/g'
* New API call: preadRichard Jones2009-11-021-0/+52
| | | | | guestfs_pread lets you do partial file reads from arbitrary places within a file. It works like the pread(2) system call.
* New API calls: truncate, truncate_size, mkdir_mode, utimens, lchown.Richard Jones2009-11-021-0/+17
| | | | | | | | | | | | | | | truncate, truncate_size: Used to truncate files to a particular size, or to zero bytes. mkdir_mode: Like mkdir but allows you to also specify the initial permissions for the new directory. utimens: Set timestamp on a file with nanosecond accuracy. lchown: Corresponding to lchown(2) syscall (we already have chown). The implementation is complicated by the fact that we had to add an Int64 parameter type to the generator.
* generator.ml: finish adding Dev_or_Path supportJim Meyering2009-08-131-2/+0
| | | | | | | | | | * src/generator.ml: Update all rules to handle Dev_or_Path. (the above changes to generator.ml are mostly mechanical) Emit a use of REQUIRE_ROOT_OR_RESOLVE_DEVICE. * daemon/upload.c (do_download): Remove use of REQUIRE_ROOT_OR_RESOLVE_DEVICE, now that it's automatically done in calling code. * daemon/file.c (do_file): Likewise.
* generator.ml: use new "Pathname" designationJim Meyering2009-08-131-45/+12
| | | | | | | | | | Nearly every file-related function in daemons/*.c is affected: Remove this pair of statements from each affected do_* function: - NEED_ROOT (return -1); - ABS_PATH (dir, return -1); and change the type of the corresponding parameter to "const char *". * src/generator.ml: Emit NEED_ROOT just once, even when there are two or more Pathname args.
* update all NEED_ROOT usesJim Meyering2009-08-131-11/+11
| | | | | | run this command: git grep -l -w NEED_ROOT|xargs perl -pi -e \ 's/(NEED_ROOT) \((.*?)\)/$1 (return $2)/'
* s/NEED_ROOT_OR_IS_DEVICE/REQUIRE_ROOT_OR_RESOLVE_DEVICE/Jim Meyering2009-08-131-1/+1
|
* manually adjust ABS_PATH uses for new semanticsJim Meyering2009-08-131-1/+1
| | | | * daemon/file.c (do_cat): fix an ABS_PATH use
* update all uses of ABS_PATHJim Meyering2009-08-131-10/+10
| | | | | | run this command: git grep -l -w ABS_PATH|xargs perl -pi -e \ 's/(?:ABS_PATH)( \(.*?,) (.*?)\)/ABS_PATH$1 return $2)/'
* change almost all uses: s/IS_DEVICE/RESOLVE_DEVICE/Jim Meyering2009-08-131-1/+1
| | | | | | Use this command: git grep -l -w IS_DEVICE|xargs perl -pi -e \ 's/\b(?:IS_DEVICE)\b( \(.*?,) (.*?)\)/RESOLVE_DEVICE$1 return $2)/'
* daemon/file.c: remove duplicate absolute-path checkJim Meyering2009-08-101-1/+0
| | | | | | * daemon/file.c (do_file): Remove redundant use of ABS_PATH. It's redundant because the preceding line invokes NEED_ROOT_OR_IS_DEVICE, which also invokes ABS_PATH.
* Convert all TABs-as-indentation to spaces.Jim Meyering2009-08-031-9/+9
| | | | | | | | | | | Do it by running this command: [exempted files are matched via .x-sc_TAB_in_indentation] git ls-files \ | pcregrep -vf .x-sc_TAB_in_indentation \ | xargs pcregrep -l '^ *\t' \ | xargs perl -MText::Tabs -ni -le \ '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
* Pass '-z' parameter to 'file' command so it looks inside compressed files.Richard Jones2009-07-281-1/+1
| | | | Also we deprecate the old 'zfile' command.
* Replace shell_quote function with %Q and %R printf specifiers.Richard Jones2009-07-281-14/+10
| | | | | | | %Q => simple shell quoted string %R => path will be prefixed by /sysroot eg. snprintf (cmd, sizeof cmd, "cat %R", path); system (cmd);
* Fix typo in error message.Richard Jones2009-07-221-1/+1
|
* Generator: Implement RBufferOut and "read-file" call.Richard W.M. Jones2009-07-211-0/+59
| | | | | | | | | This commit implements the RBufferOut type for returning arbitrary 8 bit data from calls. We also implement the guestfs_read_file call to read a whole file that can contain any 8 bit content, but up to a limit of ~ 2 MB.
* Make /sysroot path configurable.Richard Jones2009-07-181-6/+6
| | | | | | | | | Currently /sysroot is hard-coded throughout the daemon code. This patch turns the path into a variable so that we can change it in future, for example to allow standalone mode to be implemented. This patch was tested by running all the C API tests successfully.
* Implement new 'zfile' command, to show file type inside compressed files.Richard Jones2009-07-131-0/+60
|
* remove trailing blanksJim Meyering2009-07-031-1/+1
|
* Check return value from close() call.Richard Jones2009-06-221-1/+5
|
* In the daemon, change all const char * parameters to char *.Richard Jones2009-06-101-10/+10
|