master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "tool_setup.h"
26#ifdef _WIN32
27#include <tchar.h>
28#endif
30#include <signal.h>
32#ifdef HAVE_FCNTL_H
33#include <fcntl.h>
34#endif
36#include "tool_cfgable.h"
37#include "tool_doswin.h"
38#include "tool_msgs.h"
39#include "tool_operate.h"
40#include "tool_vms.h"
41#include "tool_main.h"
42#include "tool_stderr.h"
44#ifdef __VMS
45/*
46 * vms_show is a global variable, used in main() as parameter for
47 * function vms_special_exit() to allow proper curl tool exiting.
48 * Its value may be set in other tool_*.c source files thanks to
49 * forward declaration present in tool_vms.h
50 */
51int vms_show = 0;
52#endif
54#ifdef __AMIGA__
55#ifdef __GNUC__
56#define CURL_USED __attribute__((used))
57#else
58#define CURL_USED
59#endif
60static const char CURL_USED min_stack[] = "$STACK:32768";
61#endif
63#ifdef __MINGW32__
64/*
65 * There seems to be no way to escape "*" in command-line arguments with MinGW
66 * when command-line argument globbing is enabled under the MSYS shell, so turn
67 * it off.
68 */
69extern int _CRT_glob;
70int _CRT_glob = 0;
71#endif /* __MINGW32__ */
73/* if we build a static library for unit tests, there is no main() function */
74#ifndef UNITTESTS
76/*
77 * Ensure that file descriptors 0, 1 and 2 (stdin, stdout, stderr) are
78 * open before starting to run. Otherwise, the first three network
79 * sockets opened by curl could be used for input sources, downloaded data
80 * or error logs as they are effectively stdin, stdout and/or stderr.
81 *
82 * fcntl's F_GETFD instruction returns -1 if the file descriptor is closed,
83 * otherwise it returns "the file descriptor flags (which typically can only
84 * be FD_CLOEXEC, which is not set here).
85 */
86static int main_checkfds(void)
87{
88#if defined(HAVE_FCNTL) && defined(HAVE_PIPE)
89 const char * const devnull = "/dev/null";
90 int fd;
91 while((fcntl(STDIN_FILENO, F_GETFD) == -1)) {
92 fd = curlx_open(devnull, O_RDONLY);
93 if(fd < 0)
94 return 1;
95 }
96 while((fcntl(STDOUT_FILENO, F_GETFD) == -1)) {
97 fd = curlx_open(devnull, O_WRONLY);
98 if(fd < 0)
99 return 1;
100 }
101 while((fcntl(STDERR_FILENO, F_GETFD) == -1)) {
102 fd = curlx_open(devnull, O_WRONLY);
103 if(fd < 0)
104 return 1;
105 }
106#endif /* HAVE_FCNTL && HAVE_PIPE */
107 return 0;
108}
110#ifdef CURL_MEMDEBUG
111static void memory_tracking_init(void)
112{
113 char *env;
114 /* if CURL_MEMDEBUG is set, this starts memory tracking message logging */
115 env = curl_getenv("CURL_MEMDEBUG");
116 if(env) {
117 /* use the value as filename */
118 char fname[512];
119 curlx_strcopy(fname, sizeof(fname), env, strlen(env));
120 curl_free(env);
121 curl_dbg_memdebug(fname);
122 /* this weird stuff here is to make curl_free() get called before
123 curl_dbg_memdebug() as otherwise memory tracking logs a curlx_free()
124 without an alloc! */
125 }
126 /* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
127 env = curl_getenv("CURL_MEMLIMIT");
128 if(env) {
129 curl_off_t num;
130 const char *p = env;
131 if(!curlx_str_number(&p, &num, LONG_MAX))
132 curl_dbg_memlimit((long)num);
133 curl_free(env);
134 }
135}
136#else
137# define memory_tracking_init() tool_nop_stmt
138#endif
140/*
141 * curl tool main function.
142 */
143#ifdef _UNICODE
144#ifdef CURL_HAVE_DIAG
145/* GCC does not know about wmain() */
146#pragma GCC diagnostic push
147#pragma GCC diagnostic ignored "-Wmissing-prototypes"
148#pragma GCC diagnostic ignored "-Wmissing-declarations"
149#endif
150int wmain(int argc, wchar_t *argv[])
151#else
152int main(int argc, char *argv[])
153#endif
154{
155 CURLcode result = CURLE_OK;
157 CURL_MSVC_CRTDBG_INIT();
159 tool_init_stderr();
161#ifdef _WIN32
162 /* Undocumented diagnostic option to list the full paths of all loaded
163 modules. This is purposely pre-init. */
164 if(argc == 2 && !_tcscmp(argv[1], _TEXT("--dump-module-paths"))) {
165 CURL_DUMP_MODULE_PATHS(curl_mprintf);
166 return 0;
167 }
169 /* win32_init must be called before other init routines. */
170 result = win32_init();
171 if(result) {
172 errorf("(%d) Windows-specific init failed", (int)result);
173 return (int)result;
174 }
175#endif
177 if(main_checkfds()) {
178 errorf("out of file descriptors");
179 return CURLE_FAILED_INIT;
180 }
182#if defined(HAVE_SIGNAL) && defined(SIGPIPE)
183#ifdef DEBUGBUILD
184 if(!curl_getenv("CURL_SIGPIPE_DEBUG"))
185#endif
186 (void)signal(SIGPIPE, SIG_IGN);
187#endif
189 /* Initialize memory tracking */
190 memory_tracking_init();
192 /* Initialize the curl library - do not call any libcurl functions before
193 this point */
194 result = globalconf_init();
195 if(!result) {
196 /* Start our curl operation */
197 result = operate(argc, argv);
199 /* Perform the main cleanup */
200 globalconf_free();
201 }
203#ifdef _WIN32
204 /* Flush buffers of all streams opened in write or update mode */
205 fflush(NULL);
206#endif
208#ifdef __VMS
209 vms_special_exit(result, vms_show);
210#else
211 return (int)result;
212#endif
213}
215#ifdef _UNICODE
216#ifdef CURL_HAVE_DIAG
217#pragma GCC diagnostic pop
218#endif
219#endif
221#endif /* !UNITTESTS */
Diagnostics4 git calls · 25 ms
CallStatusSizeTime025 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=21 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.6 KiB · hit21 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2621 git.response.cache=HIT git.response.duration_ms=21 git.fetch.wants=5e2b965f0cebe89a68a4312249bf1cb64d5916eb git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2621 git.pkt.payload.max=2600 git.sideband.band1.bytes=2599 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e1f9d88cbc24ce
- Request
- 32465348…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format