113 #include <sys/time.h>
117 #ifdef STRCASECMP_IN_STRINGS_H
138 #define MAIL_QUEUE_INTERNAL
141 #define STR vstring_str
146 const char *queue_id)
148 const char *myname =
"mail_queue_dir";
149 static VSTRING *private_buf = 0;
151 static ARGV *hash_queue_names = 0;
160 msg_panic(
"%s: bad queue name: %s", myname, queue_name);
162 msg_panic(
"%s: bad queue id: %s", myname, queue_id);
168 if (private_buf == 0)
186 for (cpp = hash_queue_names->
argv; *cpp; cpp++) {
188 if (MQID_FIND_LG_INUM_SEPARATOR(delim, queue_id)) {
191 MQID_LG_GET_HEX_USEC(usec_buf, delim);
192 queue_id =
STR(usec_buf);
205 const char *queue_id)
207 static VSTRING *private_buf = 0;
213 if (private_buf == 0)
230 const char *myname =
"mail_queue_mkdirs";
239 msg_panic(
"%s: no slash in: %s", myname, saved_path);
248 const char *new_queue)
285 if (*queue_name == 0 || strlen(queue_name) > 100)
288 for (cp = queue_name; *cp; cp++)
311 for (cp = queue_id; *cp; cp++)
312 if (!
ISALNUM(*cp) && *cp !=
'_')
322 const char *myname =
"mail_queue_enter";
361 (
int) tp->tv_usec, pid);
362 if ((fd = open(
STR(temp_path), O_RDWR | O_CREAT | O_EXCL, mode)) >= 0)
364 if (errno == EEXIST || errno == EISDIR)
366 msg_warn(
"%s: create file %s: %m", myname,
STR(temp_path));
391 for (count = 0;; count++) {
395 MQID_LG_ENCODE_SEC(sec_buf, tp->tv_sec),
396 MQID_LG_ENCODE_USEC(usec_buf, tp->tv_usec),
397 MQID_LG_INUM_SEP, file_id);
400 MQID_SH_ENCODE_USEC(usec_buf, tp->tv_usec),
406 if (errno == EPERM || errno == EISDIR)
409 msg_warn(
"%s: rename %s to %s: %m", myname,
410 STR(temp_path),
STR(path_buf));
413 msg_fatal(
"%s: rename %s to %s: giving up", myname,
414 STR(temp_path),
STR(path_buf));
425 int flags, mode_t mode)
const char * mail_queue_dir(VSTRING *buf, const char *queue_name, const char *queue_id)
char * mystrdup(const char *str)
int mail_queue_id_ok(const char *queue_id)
#define VALID_HOSTNAME_LEN
NORETURN msg_panic(const char *fmt,...)
int REMOVE(const char *path)
int mail_queue_mkdirs(const char *path)
int mail_queue_name_ok(const char *queue_name)
VSTRING * vstring_strcpy(VSTRING *vp, const char *src)
VSTREAM * vstream_fopen(const char *path, int flags, mode_t mode)
const char * mail_queue_path(VSTRING *buf, const char *queue_name, const char *queue_id)
char * dir_forest(VSTRING *buf, const char *path, int depth)
char * var_hash_queue_names
VSTREAM * mail_queue_open(const char *queue_name, const char *queue_id, int flags, mode_t mode)
int mail_queue_rename(const char *queue_id, const char *old_queue, const char *new_queue)
VSTREAM * mail_queue_enter(const char *queue_name, mode_t mode, struct timeval *tp)
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
NORETURN msg_fatal(const char *fmt,...)
int mail_queue_remove(const char *queue_name, const char *queue_id)
ARGV * argv_split(const char *, const char *)
const char * get_file_id_fd(int fd, int long_flag)
int strcasecmp(const char *s1, const char *s2)
VSTRING * vstring_free(VSTRING *vp)
int make_dirs(const char *path, int perms)
#define CA_VSTREAM_CTL_END
#define CA_VSTREAM_CTL_PATH(v)
void vstream_control(VSTREAM *stream, int name,...)
char * split_at_right(char *string, int delimiter)
VSTRING * vstring_strcat(VSTRING *vp, const char *src)
VSTREAM * vstream_fdopen(int fd, int flags)
int WARN_UNUSED_RESULT sane_rename(const char *, const char *)