10046 mktemp should support templates not located at the end of templates

Review Request #2202 — Created July 27, 2019 and updated

bertford
illumos-gate
general

10046 mktemp should support templates not located at the end of templates

I've tested the new functionality of the mktemp command which includes a -s flag allowing a suffix to be passed. In addition, I've regression tested all existing functionality.

bob@omniosce:/tmp/tmp.DDaGIR$ mktemp
/tmp/tmp.rNaWKR
bob@omniosce:/tmp/tmp.DDaGIR$ mktemp -d
/tmp/tmp.yZa4KR
bob@omniosce:/tmp/tmp.DDaGIR$ mktemp -s .txt
/tmp/tmp.AUaiLR.txt
bob@omniosce:/tmp/tmp.DDaGIR$ mktemp -s .txt -d
/tmp/tmp.LwayLR.txt
bob@omniosce:/tmp/tmp.DDaGIR$ mktemp -s .txt XXXXXX
_daOLR.txt
bob@omniosce:/tmp/tmp.DDaGIR$ mktemp -s .txt -d XXXXXX
yDaWLR.txt
bob@omniosce:/tmp/tmp.DDaGIR$ mktemp XXXXXXX.txt
XE1aaMR.txt
bob@omniosce:/tmp/tmp.DDaGIR$ ls -l XE1aaMR.txt
-rw------- 1 bob other 0 Jul 27 00:05 XE1aaMR.txt
bob@omniosce:/tmp/tmp.DDaGIR$ mktemp -d XXXXXX.txt
48aqMR.txt
bob@omniosce:/tmp/tmp.DDaGIR$ ls -ld 48aqMR.txt/
drwx------ 2 bob other 117 Jul 27 00:05 48aqMR.txt/

  • 7
  • 0
  • 12
  • 6
  • 25
Description From Last Updated
The mkdtemps function needs to be added to this section. rm rm
Th mkdtemps function needs to be added here. Note it is not a standard interface, so we'll need to think ... rm rm
I don't think we want to cast this to an int. That'll effectively truncate a size_t down to an int ... rm rm
You should update the date for your change. rm rm
Perhaps note here that in addition to -s suffix, we also support the long form --suffix? rm rm
You should probably put suffix in markup here, I think you want \fIsuffix\fR, to indicate that it's referring to the ... rm rm
Another spot where we'll need to update the date. rm rm
yuri.pankov
  1. 
      
  2. usr/src/cmd/mktemp/mktemp.c (Diff revision 1)
     
     

    Better check the return value of asprintf being -1.

  3. usr/src/lib/libc/port/gen/mktemp.c (Diff revision 1)
     
     

    You are using mkstemps in the program, but here and in mapfile mktemps got added instead.

    1. mkstemps was already in the mapfile. mktemps was added to support mkdtemps. If this doesn't belong in the mapfile, I can remove it.

    2. After some guidance and reading usr/src/lib/README.mapfiles, I realize these entries are in the wrong place and I'll need to adjust this.

  4. usr/src/man/man1/mktemp.1 (Diff revision 1)
     
     

    template

  5. usr/src/man/man3c/mktemp.3c (Diff revision 1)
     
     

    mkstemps?

  6. usr/src/man/man3c/mktemp.3c (Diff revision 1)
     
     

    I don't see mkstemp being discussed anywhere in this man page.

  7. 
      
bertford
bertford
tsoome
  1. 
      
  2. usr/src/cmd/mktemp/mktemp.c (Diff revision 3)
     
     

    it is small nit, but it would be good to have empty line after variable declarations. Same for line 119.

  3. 
      
rm
  1. Hi, thanks for putting this together. In general, this looks pretty good. I know there are a number of comments here, but some of these come from being a side effect of adding a new symbol to libc and the headers which can be a bit trickier as we need to make sure we do things for versioning, symbols, etc.

    • I'm not sure it makes sense to add a new mktemps function as it's just used as an implementation detail of mkdtemps that you added and it has the classic TOCTTOU problem with mktemp.
    • For new manual pages you need to update the Makefile in man/man3c/Makefile to add the new symbols as links to the existing pages
    • When the above is done, you'll probably get a pacakaging failure as we'll need to make sure that the new manual page symlinks are shipped. If you look at past examples of adding symbols to libc that should hopefully make it a bit clearer
    • For more information on the symbol versioning, please see usr/lib/README.mapfiles
    • If we do add new symbols to libc, we should probably look at adding them to the symbol visibility tests. That's something I can help with once we've reached a conclusion on the rest.

    If I can help out with any of these or if I can better clarify some of these things that you've done, please let me know. Again, thanks for putting this together and looking to contribute!

    1. Hi Robert, thanks for the in depth review. I was finally able to circle back around on this and I believe I addressed the majority of the issues you raised. I still have a couple of questions, however:
      1) I reviewed the git history and updated man/man3c/Makefile but not sure how to make sure the new manual page symlinks are correct. Is there something I need to do in addition to the most recent changes?
      2) Can you let me know how I need to update the symbol visibility tests? I've added a new symbol but again, this needs reviewed for correctness.

      Your previous review suggested we need to decide if we want to add mkdtemps to libc in the first place. Without it, the mktemp cmd implementation can't cleanly create temp directories with a suffix. Let me know if we want to add this or not. If not, does adding suffix support for mktemp files make sense without adding it for directories? Is there another approach I could consider?

    2. Hi Robert, thanks for circling back on this. First let me address your questions there:

      1) What you have there looks right to me.
      2) Sure, no problem. In this case because we're basically adding a non-standard symbol (as in not something defined by POSIX, etc.) the test there would want to basically show that we haven't chagned the visibility in a strict standards environment. Since this is being put in stdlib.h, we would edit the file test/libc-tests/cfg/symbols/stdlib_h.cfg. Then you would want to add an entry like mkostemp there, but adjust it for mkdtemps.

      Regarding adding it to libc, I should have been a little bit clearer. Sorry about that. We can add symbols to libc that we consider either public or private. As we've done right now, we're basically considering this a 'public' symbol which means we'll want to support it, not break the API/ABI, etc. We can always have a symbol in libc that we consider private, which means its not documented. We would still be able to use it in the implementation of mktemp(1), so that wouldn't be a concern. Thinking on it, it's probably reasonable for us to add it and make it public in this case. It doesn't seem likely that we'll conflict with other systems here.

  2. usr/src/cmd/mktemp/mktemp.c (Diff revision 3)
     
     
     
     
    It appears the gnu option for this is --suffix. Is it worth being compatible with them in addition to the short option?
    1. The effort for me to convert this to use getopt_long would be minimal so I'd think adding --suffix for gnu compatibility is worthwhile.

  3. usr/src/cmd/mktemp/mktemp.c (Diff revision 3)
     
     
    You don't need to check both of these, for what it's worth.
  4. usr/src/head/stdlib.h (Diff revision 3)
     
     
    It looks like this is a new function that we're adding to libc. I don't see it defined elsewhere, is that correct? There also doesn't seem to be a version of this in other operating systems that I can track down.
    
    I don't think it's correct to put this in this section of the header file unfortunately. It needs to be in as section as the OpenBSD compat symbols. aka if !defined(_STRICT_SYMBOLS).
    1. This is new, correct. I believe after addressing your other concerns, there is no need for mktemps at all.

  5. usr/src/head/stdlib.h (Diff revision 3)
     
     
    See the same thing as the above.
  6. usr/src/lib/libc/port/gen/mkdtemp.c (Diff revision 3)
     
     
    Is there a reason that this doesn't just call libc_mktemps directly? I understand the desire to have an mktemp, but one gotcha with mktemps is that it has a classic time of check to time of use that at least the mkstemp* family doesn't. I'm not sure whether or not it really makes sense to have a new function for the latter.
    1. mkdtemp called mktemp but calling libc_mktemps directly here removes the need for mktemps.

  7. usr/src/lib/libc/port/mapfile-vers (Diff revision 3)
     
     
    When adding new library symbols they cannot go into an existing symbol version. They need to go into a new version.
  8. usr/src/lib/libc/port/mapfile-vers (Diff revision 3)
     
     
    Please see the above.
  9. usr/src/man/man3c/mkstemp.3c (Diff revision 3)
     
     
    The mkdtemps function needs to be added to this section.
    1. Is it still necessary to update this section? If so, should the remainder of mkstemps functions be documented here as well? If so, this man page may be a bit incomplete.

    2. It's an error that we don't document the other ones here especially because the mkdtemp family do not return file descriptors.

  10. usr/src/man/man3c/mkstemp.3c (Diff revision 3)
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    We need to update the ERRROS section to indicate which ones that mkdtemps can return. Also, we need to double check what the error behavior is on a negative or invalid suffix length.

  11. usr/src/man/man3c/mkstemp.3c (Diff revision 3)
     
     
     
    Th mkdtemps function needs to be added here. Note it is not a standard interface, so we'll need to think about whether or not it makes sense.
    1. With the current implementation, I'm not sure how else we could cleanly update the mktemp cmd to support suffixes for creating directories without adding this. Let me know if you have some thoughts.

    2. See the notes in the genearl reply.

  12. usr/src/man/man3c/mktemp.3c (Diff revision 3)
     
     
     
    The return values section needs to be updated to refer to the new function.
  13. usr/src/man/man3c/mktemp.3c (Diff revision 3)
     
     
    Is the same thing about no errors are defined true for mktemps? What about things like a negative suffix length?
  14. usr/src/man/man3c/mktemp.3c (Diff revision 3)
     
     
    The new function isn't actually part of a standard. We should probably figure out whether or not we really want to make it part of a public interface or not. My main concern with making this public is if other groups end up doing something divergent we'll be in a compatibility quagmire.
  15. 
      
bertford
  1. 
      
    1. Subbmitted the below comments in the wrong place, first time using review board, please bear with me.

  2. usr/src/cmd/mktemp/mktemp.c (Diff revision 3)
     
     
     
     

    The effort for me to convert this to use getopt_long would be minimal so I'd think adding --suffix for gnu compatibility is worthwhile.

  3. usr/src/head/stdlib.h (Diff revision 3)
     
     

    This is new, correct. I believe after addressing your other concerns, there is no need for mktemps at all.

  4. usr/src/lib/libc/port/gen/mkdtemp.c (Diff revision 3)
     
     

    mkdtemp called mktemp but calling libc_mktemps directly here removes the need for mktemps.

  5. 
      
bertford
bertford
bertford
Review request changed
rm
  1. 
      
  2. usr/src/lib/libc/port/gen/mkdtemp.c (Diff revision 6)
     
     
    I don't think we want to cast this to an int. That'll effectively truncate a size_t down to an int (so a potentially 64-bit value to a 32-bit one). I would probably cast up slen to a size_t in the comparison.
  3. usr/src/man/man1/mktemp.1 (Diff revision 6)
     
     
    You should update the date for your change.
  4. usr/src/man/man1/mktemp.1 (Diff revision 6)
     
     
    Perhaps note here that in addition to -s suffix, we also support the long form --suffix?
  5. usr/src/man/man1/mktemp.1 (Diff revision 6)
     
     

    You should probably put suffix in markup here, I think you want \fIsuffix\fR, to indicate that it's referring to the actual argument.

  6. usr/src/man/man3c/mkstemp.3c (Diff revision 6)
     
     
    Another spot where we'll need to update the date.
  7. 
      
Loading...