Merge lp:~bregma/compiz/lp-1101608 into lp:compiz/0.9.12

Proposed by Stephen M. Webb
Status: Merged
Approved by: Christopher Townsend
Approved revision: 3910
Merged at revision: 3912
Proposed branch: lp:~bregma/compiz/lp-1101608
Merge into: lp:compiz/0.9.12
Diff against target: 126 lines (+52/-30)
1 file modified
compizconfig/libcompizconfig/src/compiz.cpp (+52/-30)
To merge this branch: bzr merge lp:~bregma/compiz/lp-1101608
Reviewer Review Type Date Requested Status
Christopher Townsend Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+243377@code.launchpad.net

Commit message

libcompizconfig: reorder stat() and open() calls to eliminate a race condition

Description of the change

Reorder stat() and open() calls to eliminate a potential race condition when loading COmpiz configuration.

To post a comment you must log in.
lp:~bregma/compiz/lp-1101608 updated
3910. By Stephen M. Webb

fixed code style

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'compizconfig/libcompizconfig/src/compiz.cpp'
--- compizconfig/libcompizconfig/src/compiz.cpp 2014-08-04 09:01:36 +0000
+++ compizconfig/libcompizconfig/src/compiz.cpp 2014-12-02 11:35:42 +0000
@@ -35,7 +35,9 @@
35#include <dirent.h>35#include <dirent.h>
36#include <sys/stat.h>36#include <sys/stat.h>
37#include <errno.h>37#include <errno.h>
38#include <fcntl.h>
38#include <glib.h>39#include <glib.h>
40#include <unistd.h>
3941
40#include <libxslt/transform.h>42#include <libxslt/transform.h>
41#include <libxslt/xsltutils.h>43#include <libxslt/xsltutils.h>
@@ -1973,7 +1975,7 @@
1973 Bool success = ccsCreateDirFor (metadataCacheFileDummy.c_str ());1975 Bool success = ccsCreateDirFor (metadataCacheFileDummy.c_str ());
1974 if (!success)1976 if (!success)
1975 ccsError ("Error creating directory \"%s\"",1977 ccsError ("Error creating directory \"%s\"",
1976 metadataCacheDir.c_str ());1978 metadataCacheDir.c_str ());
1977 free (cacheBaseDir);1979 free (cacheBaseDir);
19781980
1979 if (success)1981 if (success)
@@ -2899,16 +2901,24 @@
2899#endif2901#endif
29002902
2901 // Load from .xml2903 // Load from .xml
2902 FILE *fp = fopen (xmlFilePath, "r");2904 int fd = open (xmlFilePath, O_RDONLY);
2903#ifdef USE_PROTOBUF2905#ifdef USE_PROTOBUF
2904 Bool xmlLoaded = FALSE;2906 Bool xmlLoaded = FALSE;
2905#endif2907#endif
29062908
2907 if (fp)2909 if (-1 == fd)
2908 {2910 {
2909 fclose (fp);2911 ccsError ("error %d opening %s: %s",
2910 xmlDoc *doc = xmlReadFile (xmlFilePath, NULL, 0);2912 errno, xmlFilePath, strerror(errno));
2911 if (doc)2913 }
2914 else
2915 {
2916 xmlDoc *doc = xmlReadFd (fd, xmlFilePath, NULL, 0);
2917 if (!doc)
2918 {
2919 ccsError ("error parsing %s", xmlFilePath);
2920 }
2921 else
2912 {2922 {
2913#ifdef USE_PROTOBUF2923#ifdef USE_PROTOBUF
2914 xmlLoaded =2924 xmlLoaded =
@@ -2917,6 +2927,7 @@
2917 pluginInfoPBv);2927 pluginInfoPBv);
2918 xmlFreeDoc (doc);2928 xmlFreeDoc (doc);
2919 }2929 }
2930 close (fd);
2920 }2931 }
2921 free (xmlFilePath);2932 free (xmlFilePath);
29222933
@@ -3163,30 +3174,41 @@
3163{3174{
3164 CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin);3175 CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin);
31653176
3166 xmlDoc *doc = NULL;3177 int fd = open (pPrivate->xmlFile, O_RDONLY);
3167 xmlNode **nodes;3178 if (-1 == fd)
3168 int num;3179 {
31693180 ccsError ("error %d opening %s: %s",
3170 if (stat (pPrivate->xmlFile, xmlStat))3181 errno, pPrivate->xmlFile, strerror(errno));
3171 return;3182 return;
31723183 }
3173 FILE *fp = fopen (pPrivate->xmlFile, "r");3184
3174 if (!fp)3185 if (-1 == fstat (fd, xmlStat))
3175 return;3186 {
31763187 ccsError ("error %d statting %s: %s",
3177 fclose (fp);3188 errno, pPrivate->xmlFile, strerror(errno));
3178 doc = xmlReadFile (pPrivate->xmlFile, NULL, 0);3189 close (fd);
31793190 return;
3180 nodes = getNodesFromXPath (doc, NULL, pPrivate->xmlPath, &num);3191 }
3181 if (num)3192
3182 {3193 xmlDoc *doc = xmlReadFd (fd, pPrivate->xmlFile, NULL, 0);
3183 initOptionsFromRootNode (plugin, nodes[0], pluginPBv);3194 if (!doc)
3184 if (!basicMetadata)3195 {
3185 initStringExtensionsFromRootNode (plugin, nodes[0], pluginPBv);3196 ccsError ("error parsing %s", pPrivate->xmlFile);
3186 free (nodes);3197 }
3187 }3198 else
3188 if (doc)3199 {
3200 int num = 0;
3201 xmlNode **nodes = getNodesFromXPath (doc, NULL, pPrivate->xmlPath, &num);
3202 if (num)
3203 {
3204 initOptionsFromRootNode (plugin, nodes[0], pluginPBv);
3205 if (!basicMetadata)
3206 initStringExtensionsFromRootNode (plugin, nodes[0], pluginPBv);
3207 free (nodes);
3208 }
3189 xmlFreeDoc (doc);3209 xmlFreeDoc (doc);
3210 }
3211 close (fd);
3190}3212}
31913213
3192void3214void

Subscribers

People subscribed via source and target branches