Skip to content

Commit 55db418

Browse files
committed
fix: update snapshot and status handling to use /tmp for temporary files instead of /dev/shm
1 parent 2ec8188 commit 55db418

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

docs/cn-fcc-collection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
| 河南 | | 10.254.185.70:15970 | |
2525
| 河北 | 192.168.30.150:8027 | 10.7.50.172:8027(唐山) | |
2626
| 山东 | | 124.132.240.66:15970<br>61.156.103.83:8027(青岛)<br>119.184.120.108:8027(日照) | |
27-
| 山西 | | 10.112.7.159:8027 | |
27+
| 山西 | 10.56.17.68:8072 | 10.112.7.159:8027 | |
2828
| 陕西 | 113.136.29.140:8027(西安)<br>113.136.242.134:8027(西安) | | |
2929
| 广东 | 183.59.160.61:8027(深圳)<br>183.59.168.166:8027(东莞) | | |
3030
| 广西 | 180.141.207.228:8027<br>180.141.206.228:8027<br>113.15.79.82:8027<br>171.104.238.90:8027(柳州)<br>10.255.136.86:8027(柳州)<br>10.255.165.82:8027(防城港) | | |

src/http_fetch.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,12 @@ static int build_fetch_command(char *buf, size_t bufsize,
145145

146146
if (tool == HTTP_TOOL_CURL)
147147
{
148-
/* curl command */
149148
ret = snprintf(buf, bufsize,
150-
"curl -L -f -s -S --max-time %d --connect-timeout 10 -o '%s' '%s' 2>&1; echo \"EXIT_CODE:$?\"",
149+
"curl -L -f -s -S -k --max-time %d --connect-timeout 10 -o '%s' '%s' 2>&1; echo \"EXIT_CODE:$?\"",
151150
timeout, output_file, url);
152151
}
153152
else /* HTTP_TOOL_UCLIENT_FETCH */
154153
{
155-
/* uclient-fetch command
156-
* Note: uclient-fetch does not support following redirects (-L equivalent)
157-
* and does not have separate connect/total timeout settings
158-
*/
159154
ret = snprintf(buf, bufsize,
160155
"uclient-fetch -q -T %d -O '%s' '%s' 2>&1; echo \"EXIT_CODE:$?\"",
161156
timeout, output_file, url);

src/snapshot.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,25 @@ int snapshot_init(snapshot_context_t *ctx)
4040

4141
memset(ctx, 0, sizeof(snapshot_context_t));
4242

43-
/* Create tmpfs mmap file for IDR frame accumulation */
44-
char tmpfs_path[] = "/dev/shm/rtp2httpd_idr_frame_XXXXXX";
45-
ctx->idr_frame_fd = mkstemp(tmpfs_path);
43+
/* Create tmp mmap file for IDR frame accumulation */
44+
char tmp_path[] = "/tmp/rtp2httpd_idr_frame_XXXXXX";
45+
ctx->idr_frame_fd = mkstemp(tmp_path);
4646
if (ctx->idr_frame_fd < 0)
4747
{
48-
logger(LOG_ERROR, "Snapshot: Failed to create tmpfs file: %s", strerror(errno));
48+
logger(LOG_ERROR, "Snapshot: Failed to create tmp file: %s", strerror(errno));
4949
return -1;
5050
}
5151

5252
/* Unlink immediately - file will be deleted when fd is closed */
53-
unlink(tmpfs_path);
53+
unlink(tmp_path);
5454

5555
/* Set buffer capacity */
5656
ctx->idr_frame_capacity = SNAPSHOT_BUFFER_CAPACITY;
5757

5858
/* Allocate mmap buffer */
5959
if (ftruncate(ctx->idr_frame_fd, ctx->idr_frame_capacity) < 0)
6060
{
61-
logger(LOG_ERROR, "Snapshot: Failed to truncate tmpfs file: %s", strerror(errno));
61+
logger(LOG_ERROR, "Snapshot: Failed to truncate tmp file: %s", strerror(errno));
6262
close(ctx->idr_frame_fd);
6363
return -1;
6464
}
@@ -68,7 +68,7 @@ int snapshot_init(snapshot_context_t *ctx)
6868
ctx->idr_frame_fd, 0);
6969
if (ctx->idr_frame_mmap == MAP_FAILED)
7070
{
71-
logger(LOG_ERROR, "Snapshot: Failed to mmap tmpfs file: %s", strerror(errno));
71+
logger(LOG_ERROR, "Snapshot: Failed to mmap tmp file: %s", strerror(errno));
7272
close(ctx->idr_frame_fd);
7373
return -1;
7474
}
@@ -248,8 +248,8 @@ static int snapshot_convert_to_jpeg(int idr_frame_fd, size_t idr_frame_size,
248248
*jpeg_fd = -1;
249249
*jpeg_size = 0;
250250

251-
/* Create output file in tmpfs */
252-
char output_path[] = "/dev/shm/rtp2httpd_jpeg_XXXXXX";
251+
/* Create output file in /tmp */
252+
char output_path[] = "/tmp/rtp2httpd_jpeg_XXXXXX";
253253
int output_fd = mkstemp(output_path);
254254
if (output_fd < 0)
255255
{

src/status.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,24 @@ static void json_escape_string(const char *in, char *out, size_t out_sz)
7373
/* Global pointer to shared memory */
7474
status_shared_t *status_shared = NULL;
7575

76-
/* Name for shared memory object */
77-
#define SHM_NAME "/rtp2httpd_status"
76+
/* Path for shared memory file in /tmp */
77+
static char shm_path[256] = {0};
7878

7979
/**
8080
* Initialize status tracking system
81-
* Creates and maps shared memory, then immediately closes the file descriptor.
81+
* Creates and maps shared memory file in /tmp, then immediately closes the file descriptor.
8282
* The mmap() mapping remains valid after close() per POSIX specification.
8383
*/
8484
int status_init(void)
8585
{
8686
int fd;
8787

88-
/* Create shared memory object */
89-
fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, 0600);
88+
/* Create shared memory file in /tmp */
89+
snprintf(shm_path, sizeof(shm_path), "/tmp/rtp2httpd_status_%d", getpid());
90+
fd = open(shm_path, O_CREAT | O_RDWR | O_EXCL, 0600);
9091
if (fd == -1)
9192
{
92-
logger(LOG_ERROR, "Failed to create shared memory: %s", strerror(errno));
93+
logger(LOG_ERROR, "Failed to create shared memory file: %s", strerror(errno));
9394
return -1;
9495
}
9596

@@ -98,7 +99,7 @@ int status_init(void)
9899
{
99100
logger(LOG_ERROR, "Failed to set shared memory size: %s", strerror(errno));
100101
close(fd);
101-
shm_unlink(SHM_NAME);
102+
unlink(shm_path);
102103
return -1;
103104
}
104105

@@ -109,7 +110,7 @@ int status_init(void)
109110
{
110111
logger(LOG_ERROR, "Failed to map shared memory: %s", strerror(errno));
111112
close(fd);
112-
shm_unlink(SHM_NAME);
113+
unlink(shm_path);
113114
return -1;
114115
}
115116

@@ -158,7 +159,7 @@ int status_init(void)
158159
close(status_shared->worker_notification_pipes[j]);
159160
}
160161
munmap(status_shared, sizeof(status_shared_t));
161-
shm_unlink(SHM_NAME);
162+
unlink(shm_path);
162163
return -1;
163164
}
164165

@@ -234,13 +235,13 @@ void status_cleanup(void)
234235
status_shared = NULL;
235236
}
236237

237-
/* Only worker 0 unlinks shared memory object
238-
* shm_unlink() removes the shared memory object from the filesystem.
238+
/* Only worker 0 unlinks shared memory file
239+
* unlink() removes the shared memory file from the filesystem.
239240
* If called by a non-last worker, other workers would lose access to shared memory.
240241
* In the fork model, worker 0 is the main process and exits last. */
241242
if (worker_id == 0)
242243
{
243-
shm_unlink(SHM_NAME);
244+
unlink(shm_path);
244245
logger(LOG_DEBUG, "Status tracking cleaned up (worker 0 - shared resources destroyed)");
245246
}
246247
else

0 commit comments

Comments
 (0)