/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Authors: Jeffrey Stedfast * * Copyright 2001 Ximian, Inc. (www.ximian.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include "e-mktemp.h" #include #include #include #include #include #include #include #include #include #ifdef ENABLE_THREADS #include #endif static gboolean initialized = FALSE; static GSList *temp_files = NULL; static GSList *temp_dirs = NULL; #ifdef ENABLE_THREADS static pthread_mutex_t temp_files_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t temp_dirs_lock = PTHREAD_MUTEX_INITIALIZER; #define TEMP_FILES_LOCK() pthread_mutex_lock (&temp_files_lock) #define TEMP_FILES_UNLOCK() pthread_mutex_unlock (&temp_files_lock) #define TEMP_DIRS_LOCK() pthread_mutex_lock (&temp_dirs_lock) #define TEMP_DIRS_UNLOCK() pthread_mutex_unlock (&temp_dirs_lock) #else #define TEMP_FILES_LOCK() #define TEMP_FILES_UNLOCK() #define TEMP_DIRS_LOCK() #define TEMP_DIRS_UNLOCK() #endif /* ENABLE_THREADS */ static GString * get_path (gboolean make) { GString *path; path = g_string_new ("/tmp/evolution-"); g_string_sprintfa (path, "%d-%d", (int) getuid (), (int) getpid ()); if (make) { int ret; /* shoot now, ask questions later */ ret = mkdir (path->str, S_IRWXU); if (ret == -1) { if (errno == EEXIST) { struct stat st; if (stat (path->str, &st) == -1) { /* reset errno */ errno = EEXIST; g_string_free (path, TRUE); return NULL; } /* make sure this is a directory and belongs to us... */ if (!S_ISDIR (st.st_mode) || st.st_uid != getuid ()) { /* eek! this is bad... */ g_string_free (path, TRUE); return NULL; } } else { /* some other error...do not pass go, do not collect $200 */ g_string_free (path, TRUE); return NULL; } } } return path; } static void e_mktemp_cleanup (void) { GString *path; GSList *node; TEMP_FILES_LOCK (); if (temp_files) { node = temp_files; while (node) { unlink (node->data); g_free (node->data); node = node->next; } g_slist_free (temp_files); temp_files = NULL; } TEMP_FILES_UNLOCK (); TEMP_DIRS_LOCK (); if (temp_dirs) { node = temp_dirs; while (node) { /* perform the equivalent of a rm -rf */ struct dirent *dent; DIR *dir; /* first empty out this directory of it's files... */ dir = opendir (node->data); if (dir) { while ((dent = readdir (dir)) != NULL) { /* yea...so if we contain subdirectories this won't work, but it shouldn't so we won't bother caring... */ if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) unlink (dent->d_name); } closedir (dir); } /* ...then rmdir the directory */ rmdir (node->data); g_free (node->data); node = node->next; } g_slist_free (temp_dirs); temp_dirs = NULL; } TEMP_DIRS_UNLOCK (); path = get_path (FALSE); rmdir (path->str); g_string_free (path, TRUE); } const char * e_mktemp (const char *template) { GString *path; char *ret; path = get_path (TRUE); if (!path) return NULL; g_string_append_c (path, '/'); if (template) g_string_append (path, template); else g_string_append (path, "unknown-XXXXXX"); ret = mktemp (path->str); if (ret) { TEMP_FILES_LOCK (); if (!initialized) { g_atexit (e_mktemp_cleanup); initialized = TRUE; } temp_files = g_slist_prepend (temp_files, ret); g_string_free (path, FALSE); TEMP_FILES_UNLOCK (); } else { g_string_free (path, TRUE); } return ret; } int e_mkstemp (const char *template) { GString *path; int fd; path = get_path (TRUE); if (!path) return -1; g_string_append_c (path, '/'); if (template) g_string_append (path, template); else g_string_append (path, "unknown-XXXXXX"); fd = mkstemp (path->str); if (fd != -1) { TEMP_FILES_LOCK (); if (!initialized) { g_atexit (e_mktemp_cleanup); initialized = TRUE; } temp_files = g_slist_prepend (temp_files, path->str); g_string_free (path, FALSE); TEMP_FILES_UNLOCK (); } else { g_string_free (path, TRUE); } return fd; } const char * e_mkdtemp (const char *template) { GString *path; char *tmpdir; path = get_path (TRUE); if (!path) return NULL; g_string_append_c (path, '/'); if (template) g_string_append (path, template); else g_string_append (path, "unknown-XXXXXX"); #ifdef HAVE_MKDTEMP tmpdir = mkdtemp (path->str); #else tmpdir = mktemp (path->str); if (tmpdir) { if (mkdir (tmpdir, S_IRWXU) == -1) tmpdir = NULL; } #endif if (tmpdir) { TEMP_DIRS_LOCK (); if (!initialized) { g_atexit (e_mktemp_cleanup); initialized = TRUE; } temp_dirs = g_slist_prepend (temp_dirs, tmpdir); g_string_free (path, FALSE); TEMP_DIRS_UNLOCK (); } else { g_string_free (path, TRUE); } return tmpdir; } 26b9100443ecd746082e62fe9e74d0c13fef1'>treecommitdiffstats
Commit message (Expand)AuthorAgeFilesLines
* In 2004, Red Hat has released five Indian language fonts as open sourcegabor2013-07-245-0/+83
* The Andika font is designed to work on systems and with applications thatgabor2013-07-245-0/+83
* - Changed my emailvg2013-07-222-2/+2
* Fix usage of the license framework, so that packaging can happen and the port...bapt2013-07-223-3/+3
* Update to 1.1.1zeising2013-07-172-3/+5
* Convert my ports to current standardspawel2013-07-112-12/+5
* Add x11-fonts/comfortaa-ttf.rakuco2013-06-306-0/+66
* Convert to USES=imakebapt2013-06-291-7/+3
* New USES imake to handle the dependency on imake.bapt2013-06-282-2/+2
* Fix some fonts.dir leftovers reported by poudriereantoine2013-06-283-5/+15
* Really bump portrevision.zeising2013-06-271-0/+1
* Switch to use x11-fonts/dejavu instead of x11-fonts/bitstream-vera.zeising2013-06-271-1/+1
* Update to 0.0.13.kwm2013-06-192-3/+3
* Add x11-fonts/gohufont.rakuco2013-06-185-0/+57
* Fix security issues in xorg client libraries.zeising2013-06-052-3/+3
* - Finish removal of support for Linux 2.4 in bsd.linux-apps.mk andrene2013-05-306-518/+0
* The FreeBSD x11 team proudly presentszeising2013-05-2568-401/+74
* Update to 1.0.5zeising2013-05-202-3/+3
* Fix extractionbapt2013-05-101-6/+4
* Fix buildbapt2013-05-051-1/+1
* Rely on bsdtar to autodetermine the format of the distfiles when possiblebapt2013-04-294-14/+7
* - Update to 1.050sunpoet2013-04-262-3/+3
* - Convert USE_GETTEXT to USES (part 3)ak2013-04-253-3/+3
* Finish converting the whole ports tree to USES=pkgconfigbapt2013-04-232-2/+2
* - Update to 1.23.0sunpoet2013-04-214-23/+19
* - Update to 1.017sunpoet2013-04-203-4/+5
* - Update to 1.040sunpoet2013-04-193-4/+4
* All supported version of FreeBSD have a bsdtar version that support extractin...bapt2013-04-181-8/+3
* Adding MASTER_SITE_LOCAL, in order to make it fetchable behind a proxy.thierry2013-04-131-3/+3
* Fix make fetch.rakuco2013-03-311-1/+1
* For perl@ owned ports:eadler2013-03-291-6/+2
* Style: tab -> space.eadler2013-03-291-1/+1
* update to 4.112bf2013-03-234-16/+8
* - convert USE_CMAKE to USESmakc2013-03-231-1/+1
* Convert to new options framework left unconverted ports in x* categoriesbapt2013-03-221-4/+4
* -Update to 2.3.1.mezz2013-03-204-13/+120
* "aaargh, quoted Makefile variables"eadler2013-03-193-7/+4
* Update to 1.0.4zeising2013-03-122-9/+4
* Update to 1.0.4zeising2013-03-122-9/+4
* Update to 1.0.4zeising2013-03-122-9/+4
* Update to 1.1.0zeising2013-03-122-9/+5
* Update to 1.0.7zeising2013-03-122-8/+5
* Update to 1.0.4zeising2013-03-122-9/+4
* Update to 1.3.0zeising2013-03-122-8/+7
* Update to 1.0.4zeising2013-03-122-9/+5
* Add a new xorg module, to use with USE_XORG: xorg-macros. This modulezeising2013-03-121-3/+1
* * Update the glib to 2.34.3 and gtk20 to 2.24.17 and gtk30 to 3.6.4 whichkwm2013-03-081-8/+4
* - Update *_DEPENDS on databases/py-sqlite3 after _sqlite3.so relocationlwhsu2013-03-041-6/+2
* - Update MASTER_SITESmiwi2013-03-031-3/+2
* - BROKEN distfile mismatchmiwi2013-02-211-0/+2
* Convert Makefile headers to the new format.olgeni2013-02-183-15/+3
* Update to 1.0.4zeising2013-02-142-8/+5
* - Update to 1.02 [1]culot2013-02-143-17/+32
* Various spelling correctionscrees2013-02-091-1/+1
* - Fix all cases of 'No newline at end of file' in ports treeak2013-02-015-5/+5
* New upstream release, 2.001.rakuco2013-01-282-4/+4
* - Strip header at request of original creatortabthorpe2013-01-272-10/+2
* Convert Makefile headers to the new format in my ports.olgeni2013-01-266-30/+0
* Adjust LICENSE_PERMS.rakuco2013-01-251-1/+1
* Consola Mono is a monospaced font created for programming, text editors andrakuco2013-01-256-0/+66
* Update MASTER_SITES.wxs2013-01-161-1/+1
* Update to 0.0.12.kwm2012-12-212-4/+4
* Belatedly commit removal of the original x11-fonts/gentium which wasmatthew2012-12-176-172/+0
* Rework the gentium and gentium-basic font portsmatthew2012-12-1611-107/+140
* Trim remaining untrimmed headers on my portsmatthew2012-12-151-8/+2
* Remove the header for ports I created.wxs2012-12-131-5/+0
* - Update to 1.013swills2012-12-102-3/+3
* Add x11-fonts/dina.rakuco2012-12-105-0/+57
* Undeprecate by switching to Gentoo's mirrors. The software may be obsolete, andmi2012-12-082-7/+33
* - update to 1.038bapt2012-11-242-4/+4
* Upgrade to 2.00.1.thierry2012-11-143-13/+9
* 2012-11-09 x11-fonts/tolkien-ttf: Does not fetch: there are no more public di...bapt2012-11-116-93/+0
* Fix installing this port as a user (e.g., INSTALL_AS_USER=1) bygerald2012-11-041-2/+1
* 2012-10-20 x11-themes/metacity-ana-theme: No more public distfilesbapt2012-10-2611-235/+0
* - Update MASTER_SITESjhale2012-10-252-8/+8
* - Update MASTER_SITESjhale2012-10-202-7/+3
* Mark as DEPRECATED since there are no more public distfiles available.rakuco2012-10-101-0/+3
* Clean up the headers of the ports I maintain.rakuco2012-10-071-5/+0
* Change headers of all ports maintained by me to new formatgarga2012-10-052-10/+2
* - Update to 1.010swills2012-10-032-6/+6
* Source Code Pro was designed by Paul D. Hunt as a companion to Source Sans.swills2012-09-266-0/+79
* Update to 0.0.10.1.kwm2012-09-252-3/+3
* - update to 1.036bapt2012-09-252-8/+4
* - Reassign to the heap due to mail bouncestabthorpe2012-09-221-6/+2
* Deprecate a bunch a ports with no more public distfiles (thanks ehaupt's dist...bapt2012-09-213-0/+9
* Update to 0.0.10.kwm2012-09-202-13/+6
* - update to 1.034bapt2012-09-192-6/+6
* Unbreak by setting another MASTER_SITE.rakuco2012-09-171-3/+1
* - Update to version 20120503pawel2012-09-072-14/+16
* Source Sans Pro: Adobe’s first open source type familybapt2012-08-206-0/+92
* - Reassign nork@ ports to the heaptabthorpe2012-08-161-1/+1
* Fix typos and make small modifications in COMMENT (according to Porter'scs2012-08-031-1/+1
* Fix typos in COMMENTcs2012-07-291-1/+1
* - Convert my ports to new options frameworkmakc2012-07-271-4/+6
* Fix typos in COMMENTcs2012-07-241-1/+1
* Update to version 4.38.zeising2012-07-202-5/+9
* - Convert to new options frameworksunpoet2012-07-091-11/+12
* Convert to options-ngzeising2012-07-041-20/+21
* Change maintainer address to my FreeBSD.org mail address.zeising2012-07-031-1/+1
* Upgrade to 1.1.0.thierry2012-07-033-44/+63
* s/X11BASE/LOCALBASE/, or equivalent.dougb2012-06-252-3/+3
* Update to 0.0.9.kwm2012-06-112-3/+3
* Update to version 0.7.6. [1]bsam2012-06-104-13/+17
* Add new port x11-fonts/gbdfed:makc2012-06-099-0/+112
* Convert my ports to optionsNGpawel2012-06-081-1/+3
* - Update to 20120421sylvio2012-06-072-4/+5
* - Convert USE_QT_VER=4 and QT_COMPONETS to USE_QT4miwi2012-06-061-2/+1
* - Convert all my remaining ports to OPTIONSngmatthew2012-06-052-2/+6
* - update png to 1.5.10dinoex2012-06-013-3/+3
* Convert to new options frameworkbapt2012-05-311-43/+45
* - Fix buildpav2012-05-311-0/+10
* - Fix a typomiwi2012-05-281-1/+1
* Fix plist by adding missing man pages.kwm2012-05-242-16/+16
* Update to 2.9.0.mezz2012-05-214-11/+15
* Update to 0.0.8.kwm2012-05-102-4/+4
* Add LinLibertineG fonts:bapt2012-04-246-0/+85
* Add patch from upstream to fix a C++11 issue in fontconfig. This fixes thekwm2012-04-242-1/+27
* - Mark BROKEN: unfetchablepav2012-04-201-0/+2
* Set the expiration date for all ports which depend upon linux_base-fc4 tonetchild2012-04-151-0/+2
* - update to 20120202rm2012-04-112-3/+3
* - add new "PT Mono Bold" fontrm2012-04-013-7/+8
* Fix patching.kwm2012-03-131-11/+9
* Do proper input validation for libXfont. This is for CVE-2011-2895.kwm2012-03-132-0/+104
* Update to 1.202cs2012-03-052-3/+3
* - switch to self-made versioned distfile namesrm2012-02-292-9/+9
* The fonts xorg meta port should depend on the fonts sub-meta portskwm2012-02-281-6/+6
* Roboto is a sans serif typeface family designed to be modern yetrm2012-02-236-0/+79
* - actually bump PORTREVISION, sorry for this.rm2012-02-151-1/+1
* - update checksum for PTMonoOFL.zip once again. This font was updated upstream.rm2012-02-152-3/+3
* Update maintainer address to matthew@FreeBSD.orgmatthew2012-02-102-2/+2
* - Update to 4.7.5jgh2012-02-074-39/+58
* - update PT Mono font to 1.001 (released at 23 Jan)rm2012-01-302-3/+3
* - Update to 0.5.14miwi2012-01-29