11#include " cdocker.h"
22
3- #include < iostream>
43#include < cstdlib>
54#include < cstring>
65#include < cctype>
76#include < stdexcept>
8- #include < cerrno>
97#include < cstdio>
108
119extern " C" {
12- #include < limits.h>
1310#include < sys/dir.h>
1411#include < unistd.h>
15- #include < signal.h>
1612#include < sched.h>
1713#include < fcntl.h>
1814#include < sys/types.h>
@@ -70,14 +66,14 @@ CDocker::CDocker() : dockerPath("/var/lib/docker/containers"), dockerConfig("con
7066}
7167
7268void CDocker::loadConfigDirectory () {
73- DIR *dir = NULL ;
69+ DIR *dir = nullptr ;
7470 const char *dpath = this ->dockerPath .c_str ();
75- struct dirent *ent = NULL ;
71+ struct dirent *ent = nullptr ;
7672 char fbuf[PATH_MAX];
7773 memset (fbuf, 0 , PATH_MAX);
7874
79- if ((dir = opendir (dpath)) != NULL ) {
80- while ((ent = readdir (dir)) != NULL ) {
75+ if ((dir = opendir (dpath)) != nullptr ) {
76+ while ((ent = readdir (dir)) != nullptr ) {
8177 if (strcmp (ent->d_name , " ." ) == 0 ) {
8278 continue ;
8379 } else if (strcmp (ent->d_name , " .." ) == 0 ) {
@@ -87,7 +83,7 @@ void CDocker::loadConfigDirectory() {
8783 this ->loadConfigV2 ((const char *)fbuf);
8884 }
8985 closedir (dir);
90- dir = NULL ;
86+ dir = nullptr ;
9187 } else {
9288 perror (" opendir()" );
9389 throw std::runtime_error (" opendir failed." );
@@ -97,7 +93,7 @@ void CDocker::loadConfigDirectory() {
9793void CDocker::loadConfigV2 (const char *configFile) {
9894 FILE *f;
9995 size_t lSize = 0 ;
100- char *fcontent = NULL ;
96+ char *fcontent = nullptr ;
10197 std::string hostname;
10298 size_t lRead = 0 ;
10399 int pid;
@@ -115,7 +111,7 @@ void CDocker::loadConfigV2(const char *configFile) {
115111 }
116112
117113 fcontent = (char *)calloc (lSize, sizeof (char ));
118- if (fcontent == NULL ) {
114+ if (fcontent == nullptr ) {
119115 fclose (f);
120116 throw std::runtime_error (" Calloc failed. Out of memory" );
121117 }
@@ -152,19 +148,19 @@ int CDocker::findKeyString(char *fcontent, const char *k, std::string *ret)
152148{
153149 char fdata[DBUF_SIZE_SMALL];
154150 memset (fdata, 0 , DBUF_SIZE_SMALL);
155- char *tmp = NULL ;
156- char *tmp_e = NULL ;
151+ char *tmp = nullptr ;
152+ char *tmp_e = nullptr ;
157153 std::string lookupString;
158154 lookupString += " \" " ;
159155 lookupString += k;
160156 lookupString += " \" :" ;
161157 tmp = strstr (fcontent, lookupString.c_str ());
162- if (tmp == NULL )
158+ if (tmp == nullptr )
163159 return -1 ;
164160 if (strlen (tmp) > strlen (k)+4 )
165161 tmp+=strlen (k)+4 ;
166162 tmp_e = strchr (tmp, ' "' );
167- if (tmp_e == NULL )
163+ if (tmp_e == nullptr )
168164 return -2 ;
169165 if (tmp_e-tmp <= 1 )
170166 return -3 ;
@@ -177,25 +173,25 @@ int CDocker::findKeyInt(char *fcontent, const char *k, int *ret)
177173{
178174 char fdata[DBUF_SIZE_SMALL];
179175 memset (fdata, 0 , DBUF_SIZE_SMALL);
180- char *tmp = NULL ;
181- char *tmp_e = NULL ;
176+ char *tmp = nullptr ;
177+ char *tmp_e = nullptr ;
182178 int rint = 0 ;
183179 std::string lookupString;
184180 lookupString += " \" " ;
185181 lookupString += k;
186182 lookupString += " \" :" ;
187183 tmp = strstr (fcontent, lookupString.c_str ());
188- if (tmp == NULL )
184+ if (tmp == nullptr )
189185 return -1 ;
190186 if (strlen (tmp) > strlen (k)+3 )
191187 tmp+=strlen (k)+3 ;
192188
193189 tmp_e = tmp;
194- while (tmp_e != NULL && isdigit (*tmp_e)) {
190+ while (tmp_e != nullptr && isdigit (*tmp_e)) {
195191 tmp_e++;
196192 }
197193
198- if (tmp_e == NULL || tmp_e == tmp)
194+ if (tmp_e == nullptr || tmp_e == tmp)
199195 return -2 ;
200196 if (tmp_e-tmp <= 1 )
201197 return -3 ;
@@ -209,7 +205,7 @@ int CDocker::findKeyInt(char *fcontent, const char *k, int *ret)
209205void CDocker::setNSByHostname (std::string hostname) {
210206 std::map<std::string, CDockerContainer>::iterator it;
211207 char fbuf[PATH_MAX];
212- NamespaceFile *nsfile = NULL ;
208+ NamespaceFile *nsfile = nullptr ;
213209
214210 std::vector<class NamespaceFile *> namespace_files;
215211 namespace_files.push_back (new NamespaceFile (CLONE_NEWIPC, " ipc" ));
@@ -242,7 +238,7 @@ void CDocker::setNSByHostname(std::string hostname) {
242238 }
243239 nsfile->closefd ();
244240 delete nsfile;
245- namespace_files[i] = NULL ;
241+ namespace_files[i] = nullptr ;
246242 }
247243}
248244
@@ -254,7 +250,7 @@ int CDocker::run(std::string hostname, std::vector<std::string> args) {
254250 char cwd[PATH_MAX];
255251 memset (cwd,0 ,PATH_MAX);
256252
257- if (getcwd (cwd, PATH_MAX) == NULL ) {
253+ if (getcwd (cwd, PATH_MAX) == nullptr ) {
258254 perror (" ERROR: getcwd()" );
259255 throw std::runtime_error ( " getcwd failed" );
260256 }
0 commit comments