Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 594382 | Differences between
and this patch

Collapse All | Expand All

(-)file_not_specified_in_diff (-41 / +45 lines)
Line  Link Here
0
-- a/accept-confirmation.cpp
0
++ b/accept-confirmation.cpp
Lines 52-58 Link Here
52
    for (rc = read(fd, tmp, sizeof(tmp)); rc > 0; rc = read(fd, tmp, sizeof(tmp)))
52
    for (rc = read(fd, tmp, sizeof(tmp)); rc > 0; rc = read(fd, tmp, sizeof(tmp)))
53
      mail.append(tmp, rc);
53
      mail.append(tmp, rc);
54
    if (rc < 0)
54
    if (rc < 0)
55
      throw system_error(string("Failed to read mail file '") + filename + "'");
55
      throw Mapson::system_error(string("Failed to read mail file '") + filename + "'");
56
    deliver(mail);
56
    deliver(mail);
57
    unlink(filename.c_str());
57
    unlink(filename.c_str());
58
  }
58
  }
59
-- a/address-db.cpp
59
++ b/address-db.cpp
Lines 26-32 Link Here
26
26
27
  fd = open(filename.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
27
  fd = open(filename.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
28
  if (fd < 0)
28
  if (fd < 0)
29
    throw system_error(string("Can't open address db '") +
29
    throw Mapson::system_error(string("Can't open address db '") +
30
                      filename + "' for reading");
30
                      filename + "' for reading");
31
  fd_sentry sentry(fd);
31
  fd_sentry sentry(fd);
32
32
Lines 36-42 Link Here
36
  lock.l_start  = 0;
36
  lock.l_start  = 0;
37
  lock.l_len    = 0;
37
  lock.l_len    = 0;
38
  if (fcntl(fd, F_SETLKW, &lock) != 0)
38
  if (fcntl(fd, F_SETLKW, &lock) != 0)
39
    throw system_error(string("Can't lock file '") + filename + "'");
39
    throw Mapson::system_error(string("Can't lock file '") + filename + "'");
40
40
41
  // Read the file into memory.
41
  // Read the file into memory.
42
42
Lines 47-53 Link Here
47
       rc = read(fd, buffer, sizeof(buffer)))
47
       rc = read(fd, buffer, sizeof(buffer)))
48
    data.append(buffer, rc);
48
    data.append(buffer, rc);
49
  if (rc < 0)
49
  if (rc < 0)
50
    throw system_error(string("Failed to read address db '") +
50
    throw Mapson::system_error(string("Failed to read address db '") +
51
                      filename + "' into memory");
51
                      filename + "' into memory");
52
52
53
  // Success. Don't close the file descriptor.
53
  // Success. Don't close the file descriptor.
Lines 107-113 Link Here
107
  {
107
  {
108
    ssize_t rc = write(fd, data.data()+len, data.size()-len);
108
    ssize_t rc = write(fd, data.data()+len, data.size()-len);
109
    if (rc < 0)
109
    if (rc < 0)
110
      throw system_error(string("Failed writing to the address db '") + filename + "'");
110
      throw Mapson::system_error(string("Failed writing to the address db '") + filename + "'");
111
    else
111
    else
112
      len += rc;
112
      len += rc;
113
  }
113
  }
114
-- a/config.cpp
114
++ b/config.cpp
Lines 70-78 Link Here
70
    string tmp = string(name) + "=" + value;
70
    string tmp = string(name) + "=" + value;
71
    char* env = strdup(tmp.c_str());
71
    char* env = strdup(tmp.c_str());
72
    if (env == 0)
72
    if (env == 0)
73
      throw system_error("strdup() failed");
73
      throw Mapson::system_error("strdup() failed");
74
    if (putenv(env) != 0)
74
    if (putenv(env) != 0)
75
      throw system_error("putenv() failed");
75
      throw Mapson::system_error("putenv() failed");
76
  }
76
  }
77
}
77
}
78
78
Lines 84-90 Link Here
84
84
85
  pwd_sentry sentry(getpwuid(getuid()));
85
  pwd_sentry sentry(getpwuid(getuid()));
86
  if (sentry.pwd == 0)
86
  if (sentry.pwd == 0)
87
    throw system_error("Can't get my user name");
87
    throw Mapson::system_error("Can't get my user name");
88
  log_file.assign(sentry.pwd->pw_dir).append("/.mapson/log");
88
  log_file.assign(sentry.pwd->pw_dir).append("/.mapson/log");
89
  spool_dir.assign(sentry.pwd->pw_dir).append("/.mapson/spool");
89
  spool_dir.assign(sentry.pwd->pw_dir).append("/.mapson/spool");
90
  address_db.assign(sentry.pwd->pw_dir).append("/.mapson/address-db");
90
  address_db.assign(sentry.pwd->pw_dir).append("/.mapson/address-db");
91
-- a/deliver.cpp
91
++ b/deliver.cpp
Lines 31-41 Link Here
31
31
32
    FILE* fh = popen(config->mailbox.c_str()+1, "w");
32
    FILE* fh = popen(config->mailbox.c_str()+1, "w");
33
    if (fh == NULL)
33
    if (fh == NULL)
34
      throw system_error(string("Can't start delivery pipe '") + config->mailbox + "'");
34
      throw Mapson::system_error(string("Can't start delivery pipe '") + config->mailbox + "'");
35
    int len = fwrite(mail.data(), mail.size(), 1, fh);
35
    int len = fwrite(mail.data(), mail.size(), 1, fh);
36
    pclose(fh);
36
    pclose(fh);
37
    if (len != 1)
37
    if (len != 1)
38
      throw system_error(string("Failed to pipe to MTA process '") + config->mailbox + "'");
38
      throw Mapson::system_error(string("Failed to pipe to MTA process '") + config->mailbox + "'");
39
  }
39
  }
40
  else
40
  else
41
  {
41
  {
Lines 43-49 Link Here
43
43
44
    int fd = open(config->mailbox.c_str(), O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
44
    int fd = open(config->mailbox.c_str(), O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
45
    if (fd < 0)
45
    if (fd < 0)
46
      throw system_error(string("Can't open mailbox file '") + config->mailbox + "' for writing");
46
      throw Mapson::system_error(string("Can't open mailbox file '") + config->mailbox + "' for writing");
47
    fd_sentry sentry(fd);
47
    fd_sentry sentry(fd);
48
48
49
    struct flock lock;
49
    struct flock lock;
Lines 52-64 Link Here
52
    lock.l_start  = 0;
52
    lock.l_start  = 0;
53
    lock.l_len    = 0;
53
    lock.l_len    = 0;
54
    if (fcntl(fd, F_SETLKW, &lock) != 0)
54
    if (fcntl(fd, F_SETLKW, &lock) != 0)
55
      throw system_error(string("Can't lock file '") + config->mailbox + "'");
55
      throw Mapson::system_error(string("Can't lock file '") + config->mailbox + "'");
56
56
57
    for (size_t len = 0; len < mail.size(); )
57
    for (size_t len = 0; len < mail.size(); )
58
    {
58
    {
59
      ssize_t rc = write(fd, mail.data()+len, mail.size()-len);
59
      ssize_t rc = write(fd, mail.data()+len, mail.size()-len);
60
      if (rc < 0)
60
      if (rc < 0)
61
        throw system_error(string("Failed writing to the mailbox file '") + config->mailbox + "'");
61
        throw Mapson::system_error(string("Failed writing to the mailbox file '") + config->mailbox + "'");
62
      else
62
      else
63
        len += rc;
63
        len += rc;
64
    }
64
    }
65
-- a/lines2regex.cpp
65
++ b/lines2regex.cpp
Lines 29-35 Link Here
29
    if (errno == ENOENT)
29
    if (errno == ENOENT)
30
      return "";
30
      return "";
31
    else
31
    else
32
      throw system_error(string("Can't open regex db '") +
32
      throw Mapson::system_error(string("Can't open regex db '") +
33
                        filename + "' for reading");
33
                        filename + "' for reading");
34
  }
34
  }
35
  fd_sentry sentry(fd);
35
  fd_sentry sentry(fd);
Lines 40-46 Link Here
40
  lock.l_start  = 0;
40
  lock.l_start  = 0;
41
  lock.l_len    = 0;
41
  lock.l_len    = 0;
42
  if (fcntl(fd, F_SETLKW, &lock) != 0)
42
  if (fcntl(fd, F_SETLKW, &lock) != 0)
43
    throw system_error(string("Can't lock file '") + filename + "'");
43
    throw Mapson::system_error(string("Can't lock file '") + filename + "'");
44
44
45
  // Read the file into memory.
45
  // Read the file into memory.
46
46
Lines 52-58 Link Here
52
       rc = read(fd, buffer, sizeof(buffer)))
52
       rc = read(fd, buffer, sizeof(buffer)))
53
    data.append(buffer, rc);
53
    data.append(buffer, rc);
54
  if (rc < 0)
54
  if (rc < 0)
55
    throw system_error(string("Failed to read regex db '") +
55
    throw Mapson::system_error(string("Failed to read regex db '") +
56
                      filename + "' into memory");
56
                      filename + "' into memory");
57
57
58
  // Walk through the lines and compile the regexes.
58
  // Walk through the lines and compile the regexes.
59
-- a/log.cpp
59
++ b/log.cpp
Lines 30-39 Link Here
30
  char buf[64];
30
  char buf[64];
31
  time_t tstamp = time(0);
31
  time_t tstamp = time(0);
32
  if (tstamp == static_cast<time_t>(-1))
32
  if (tstamp == static_cast<time_t>(-1))
33
    throw system_error("time(2) failed");
33
    throw Mapson::system_error("time(2) failed");
34
  struct tm* tmtime = localtime(&tstamp);
34
  struct tm* tmtime = localtime(&tstamp);
35
  if (tmtime == 0)
35
  if (tmtime == 0)
36
    throw system_error("localtime(3) failed");
36
    throw Mapson::system_error("localtime(3) failed");
37
  strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tmtime);
37
  strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tmtime);
38
  return buf;
38
  return buf;
39
}
39
}
Lines 42-48 Link Here
42
{
42
{
43
  fileh.file = fopen(file, "a");
43
  fileh.file = fopen(file, "a");
44
  if (fileh.file == 0)
44
  if (fileh.file == 0)
45
    throw system_error(string("Could not open log file ") + file);
45
    throw Mapson::system_error(string("Could not open log file ") + file);
46
46
47
  struct flock lock;
47
  struct flock lock;
48
  lock.l_type = F_WRLCK;
48
  lock.l_type = F_WRLCK;
Lines 50-56 Link Here
50
  lock.l_start  = 0;
50
  lock.l_start  = 0;
51
  lock.l_len    = 0;
51
  lock.l_len    = 0;
52
  if (fcntl(fileno(fileh.file), F_SETLKW, &lock) != 0)
52
  if (fcntl(fileno(fileh.file), F_SETLKW, &lock) != 0)
53
    throw system_error(string("Can't lock file '") + file + "'");
53
    throw Mapson::system_error(string("Can't lock file '") + file + "'");
54
}
54
}
55
55
56
void _debug(const char* fmt, ...)
56
void _debug(const char* fmt, ...)
57
-- a/mapson.cpp
57
++ b/mapson.cpp
Lines 62-68 Link Here
62
62
63
      fd = open(argv[i], O_RDONLY, 0);
63
      fd = open(argv[i], O_RDONLY, 0);
64
      if (fd < 0)
64
      if (fd < 0)
65
        throw system_error("Can't open file for reading");
65
        throw Mapson::system_error("Can't open file for reading");
66
      fd_sentry sentry(fd);
66
      fd_sentry sentry(fd);
67
      string mail;
67
      string mail;
68
      for (rc = read(fd, buffer, sizeof(buffer));
68
      for (rc = read(fd, buffer, sizeof(buffer));
Lines 72-78 Link Here
72
        mail.append(buffer, rc);
72
        mail.append(buffer, rc);
73
      }
73
      }
74
      if (rc < 0)
74
      if (rc < 0)
75
        throw system_error("Failed to read from file");
75
        throw Mapson::system_error("Failed to read from file");
76
76
77
      // Extract the mail addresses.
77
      // Extract the mail addresses.
78
78
Lines 196-202 Link Here
196
    mail.append(buffer, rc);
196
    mail.append(buffer, rc);
197
  }
197
  }
198
  if (rc < 0)
198
  if (rc < 0)
199
    throw system_error("Failed to read mail from standard input");
199
    throw Mapson::system_error("Failed to read mail from standard input");
200
200
201
  // Check whether the mail contains a valid cookie. If it does,
201
  // Check whether the mail contains a valid cookie. If it does,
202
  // mail will be replaced with the original e-mail, that was
202
  // mail will be replaced with the original e-mail, that was
203
-- a/parse-config-file.cpp
203
++ b/parse-config-file.cpp
Lines 55-61 Link Here
55
55
56
  std::ifstream file(filename);
56
  std::ifstream file(filename);
57
  if (!file)
57
  if (!file)
58
    throw system_error(std::string("parse_config_file() failed to open '") + filename + "'");
58
    throw Mapson::system_error(std::string("parse_config_file() failed to open '") + filename + "'");
59
59
60
  // Now we read line by line and process each one seperately.
60
  // Now we read line by line and process each one seperately.
61
61
62
-- a/request-confirmation.cpp
62
++ b/request-confirmation.cpp
Lines 157-163 Link Here
157
  string filename = config->request_for_confirmation_file;
157
  string filename = config->request_for_confirmation_file;
158
  int fd = multi_open(filename, O_RDONLY, S_IRUSR | S_IWUSR);
158
  int fd = multi_open(filename, O_RDONLY, S_IRUSR | S_IWUSR);
159
  if (fd < 0)
159
  if (fd < 0)
160
    throw system_error(string("Can't open request-mail template file '") + filename + "' for reading");
160
    throw Mapson::system_error(string("Can't open request-mail template file '") + filename + "' for reading");
161
  fd_sentry sentry(fd);
161
  fd_sentry sentry(fd);
162
162
163
  // Read the file into memory.
163
  // Read the file into memory.
Lines 167-173 Link Here
167
  for (rc = read(fd, buffer, sizeof(buffer)); rc > 0; rc = read(fd, buffer, sizeof(buffer)))
167
  for (rc = read(fd, buffer, sizeof(buffer)); rc > 0; rc = read(fd, buffer, sizeof(buffer)))
168
    mail_template.append(buffer, rc);
168
    mail_template.append(buffer, rc);
169
  if (rc < 0)
169
  if (rc < 0)
170
    throw system_error(string("Failed to read request-mail template file '") + filename + "' into memory");
170
    throw Mapson::system_error(string("Failed to read request-mail template file '") + filename + "' into memory");
171
171
172
  // Expand variables in the template.
172
  // Expand variables in the template.
173
173
Lines 180-190 Link Here
180
  debug(("Executing mail transport agent '%s'.", config->mta.c_str()));
180
  debug(("Executing mail transport agent '%s'.", config->mta.c_str()));
181
  FILE* fh = popen(config->mta.c_str(), "w");
181
  FILE* fh = popen(config->mta.c_str(), "w");
182
  if (fh == NULL)
182
  if (fh == NULL)
183
    throw system_error(string("Can't start MTA '") + config->mta + "'");
183
    throw Mapson::system_error(string("Can't start MTA '") + config->mta + "'");
184
  if (fwrite(mail_template.data(), mail_template.size(), 1, fh) != 1)
184
  if (fwrite(mail_template.data(), mail_template.size(), 1, fh) != 1)
185
  {
185
  {
186
    pclose(fh);
186
    pclose(fh);
187
    throw system_error(string("Failed to pipe to MTA process '") + config->mta + "'");
187
    throw Mapson::system_error(string("Failed to pipe to MTA process '") + config->mta + "'");
188
  }
188
  }
189
  pclose(fh);
189
  pclose(fh);
190
}
190
}
191
-- a/spool.cpp
191
++ b/spool.cpp
Lines 44-56 Link Here
44
  info("Spooling e-mail '%s' as '%s'.", config->message_id.c_str(), filename.c_str());
44
  info("Spooling e-mail '%s' as '%s'.", config->message_id.c_str(), filename.c_str());
45
  int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
45
  int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
46
  if (fd < 0)
46
  if (fd < 0)
47
    throw system_error(string("Can't open spool file '") + filename + "' for writing");
47
    throw Mapson::system_error(string("Can't open spool file '") + filename + "' for writing");
48
  fd_sentry sentry(fd);
48
  fd_sentry sentry(fd);
49
  for (size_t len = 0; len < mail.size(); )
49
  for (size_t len = 0; len < mail.size(); )
50
  {
50
  {
51
    ssize_t rc = write(fd, mail.data()+len, mail.size()-len);
51
    ssize_t rc = write(fd, mail.data()+len, mail.size()-len);
52
    if (rc < 0)
52
    if (rc < 0)
53
      throw system_error(string("Failed writing to the spool file '") + filename + "'");
53
      throw Mapson::system_error(string("Failed writing to the spool file '") + filename + "'");
54
    else
54
    else
55
      len += rc;
55
      len += rc;
56
  }
56
  }
57
-- a/system-error.hpp
57
++ b/system-error.hpp
Lines 23-28 Link Here
23
#include <string>
23
#include <string>
24
#include <cstring>
24
#include <cstring>
25
25
26
namespace Mapson {
27
26
class system_error : public std::runtime_error
28
class system_error : public std::runtime_error
27
{
29
{
28
public:
30
public:
Lines 43-46 Link Here
43
  }
45
  }
44
};
46
};
45
47
48
} // namespace Mapson
49
46
#endif
50
#endif

Return to bug 594382