Raymond Toy pushed to branch issue-393-os-common-getpwuid at cmucl / cmucl

Commits:

2 changed files:

Changes:

  • src/code/unix.lisp
    ... ... @@ -2540,14 +2540,24 @@
    2540 2540
           (unwind-protect
    
    2541 2541
     	   (progn
    
    2542 2542
     	     (setf result
    
    2543
    -		   (alien-funcall
    
    2544
    -		    (extern-alien "os_getpwuid"
    
    2545
    -				  (function (* (struct passwd))
    
    2546
    -					    uid-t))
    
    2547
    -		    uid))
    
    2543
    +		   (locally
    
    2544
    +		       ;; Inhibit warnings about not being able to
    
    2545
    +		       ;; optimize away %sap-alien and doing runtime
    
    2546
    +		       ;; allocation.
    
    2547
    +		       (declare (optimize (ext:inhibit-warnings 3)))
    
    2548
    +		     (alien-funcall
    
    2549
    +		      (extern-alien "os_getpwuid"
    
    2550
    +				    (function (* (struct passwd))
    
    2551
    +					      uid-t))
    
    2552
    +		      uid)))
    
    2548 2553
     	     (if (null-alien result)
    
    2549 2554
     		 (values nil (unix-errno))
    
    2550
    -		 (let ((passwd (deref result)))
    
    2555
    +		 (let ((passwd (locally
    
    2556
    +				   ;; Inhibit warnings about not being able to
    
    2557
    +				   ;; optimize away %sap-alien and doing runtime
    
    2558
    +				   ;; allocation.
    
    2559
    +				   (declare (optimize (ext:inhibit-warnings 3)))
    
    2560
    +				 (deref result))))
    
    2551 2561
     		   (make-user-info
    
    2552 2562
     		    :name (string (cast (slot passwd 'pw-name) c-call:c-string))
    
    2553 2563
     		    :password (string (cast (slot passwd 'pw-passwd) c-call:c-string))
    
    ... ... @@ -2557,16 +2567,14 @@
    2557 2567
     		    :gecos (string-decode (cast (slot passwd 'pw-gecos) c-call:c-string)
    
    2558 2568
     					  :default)
    
    2559 2569
     		    ;; The home directory could be unicode 
    
    2560
    -		    :dir (%file->name (cast (slot passwd 'pw-dir) c-call:c-string))
    
    2570
    +		    :dir (%file->name (string (cast (slot passwd 'pw-dir) c-call:c-string)))
    
    2561 2571
     		    :shell (string (cast (slot passwd 'pw-shell) c-call:c-string))))))
    
    2562 2572
     	(unless (null-alien result)
    
    2563
    -	  (let ((passwd (deref result)))
    
    2564
    -	    (free-alien (slot passwd 'pw-name))
    
    2565
    -	    (free-alien (slot passwd 'pw-passwd))
    
    2566
    -	    (free-alien (slot passwd 'pw-gecos))
    
    2567
    -	    (free-alien (slot passwd 'pw-dir))
    
    2568
    -	    (free-alien (slot passwd 'pw-shell)))
    
    2569
    -	  (free-alien result))))))
    
    2573
    +	  (alien-funcall
    
    2574
    +	   (extern-alien "os_free_getpwuid"
    
    2575
    +			 (function c-call:void
    
    2576
    +				   (* (struct passwd))))
    
    2577
    +	   result))))))
    
    2570 2578
     
    
    2571 2579
     
    
    2572 2580
     ;;; Getrusage is not provided in the C library on Solaris 2.4, and is
    

  • src/lisp/os-common.c
    ... ... @@ -936,6 +936,16 @@ os_get_user_homedir(const char* name, int *status)
    936 936
         return NULL;
    
    937 937
     }
    
    938 938
         
    
    939
    +
    
    940
    +/*
    
    941
    + * Get the passwd info for the user id UID.  If the uid does not
    
    942
    + * exist, return NULL.  Otherwise, return a passwd struct that has the
    
    943
    + * slots filled in that are needed to create the USER-INFO structure.
    
    944
    + * All other slots in passwd are undefined.
    
    945
    + *
    
    946
    + * The caller MUST call os_free_getpwuid() to free the space allocated
    
    947
    + * by os_getpwuid().
    
    948
    + */
    
    939 949
     struct passwd*
    
    940 950
     os_getpwuid(uid_t uid)
    
    941 951
     {
    
    ... ... @@ -994,3 +1004,18 @@ again:
    994 1004
         
    
    995 1005
         return result;
    
    996 1006
     }
    
    1007
    +
    
    1008
    +/*
    
    1009
    + * Free the space allocated for the passwd struct returned by
    
    1010
    + * os_getpwuid().
    
    1011
    + */
    
    1012
    +void
    
    1013
    +os_free_getpwuid(struct passwd* pwd)
    
    1014
    +{
    
    1015
    +    free(pwd->pw_name);
    
    1016
    +    free(pwd->pw_passwd);
    
    1017
    +    free(pwd->pw_gecos);
    
    1018
    +    free(pwd->pw_dir);
    
    1019
    +    free(pwd->pw_shell);
    
    1020
    +    free(pwd);
    
    1021
    +}