[go: up one dir, main page]

|
|
Log in / Subscribe / Register

The trouble with symbolic links

The trouble with symbolic links

Posted Jul 8, 2022 0:46 UTC (Fri) by zaitseff (subscriber, #851)
In reply to: The trouble with symbolic links by mpr22
Parent article: The trouble with symbolic links

Indeed. However, I can't quite see how to use these: something I didn't mention is that mkdir() is only run if writing a data file: if no data file is saved (a user-initiated operation), no directory is created. So I'm not sure how to avoid the TOCTOU problem in such a situation.


to post comments

The trouble with symbolic links

Posted Jul 8, 2022 1:20 UTC (Fri) by mpr22 (subscriber, #60784) [Link] (1 responses)

  1. Any time you access a file without knowing which data directory to use, search for your preferred data directory with open() and fstat().
  2. If you find one of your desired directories, retain the file descriptor as well as the pathname, and use openat() with the file descriptor for all further activities relating to your preferred data directory.
  3. If you don't find any of the desired data directories, then don't retain the result at all; next time you try to access a file, start fresh from step 1.

Safely creating the directory if it doesn't exist is still kind of a pain in the neck, because you can't combine the operations of "make a directory" and "open a file descriptor pointing to the directory" into a single indivisible syscall.

The trouble with symbolic links

Posted Jul 8, 2022 4:16 UTC (Fri) by magfr (subscriber, #16052) [Link]

And neither the cd nor the mkdir shell builtin provides a flag to create a directory and chdir to it in one operation.
Probably for that exact reason but I have wished for it at times.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds