Commit Graph

43 Commits

Author SHA1 Message Date
cb7cfa58ab fix: guard os.Args access for wasm which panics when building (#4762)
This pull request improves the reliability and safety of server restart
and reload operations by ensuring the correct retrieval of the current
executable path and process arguments. It replaces direct usage of
`os.Args[0]` with a more robust approach using `gfile.SelfPath()`, and
adds error handling for cases where the executable path cannot be
determined. Additionally, it introduces a helper function to safely
obtain process arguments, and removes an unnecessary import.

**Executable Path Handling and Error Checking:**

- Replaced usage of `os.Args[0]` with `gfile.SelfPath()` throughout the
server admin and process management code to reliably determine the
current executable path; added checks and error responses when the path
cannot be determined.
[[1]](diffhunk://#diff-0d174b149c56c4aa7ffeba2be94d16dc1b8000933f1f2a2e6bf011acdad3272fL122-R134)
[[2]](diffhunk://#diff-0d174b149c56c4aa7ffeba2be94d16dc1b8000933f1f2a2e6bf011acdad3272fL168-R184)
[[3]](diffhunk://#diff-3b4265be7ef0335b832dacfc2fc7ddc0f9dfae5b81340ff57d2b6a526c60d9e1L62-R65)
- Added early returns in initialization functions if `os.Args` is empty,
preventing potential panics or misbehavior when the argument list is
missing.
[[1]](diffhunk://#diff-0aa99f033274ea60b9c466ae4fc98d0816ec13781d8ec787fb3ef106a49a79ecR35-R37)
[[2]](diffhunk://#diff-5782fa47aa858b8e8358fd50353b050ee30418b7844b36e313e9c6d01188c092R47-R49)

**Process Argument Handling:**

- Introduced the `getCurrentProcessArgs()` helper function to safely
return process arguments (excluding the program name), ensuring correct
behavior even if no arguments are provided. Updated process creation
calls to use this helper.

**Code Cleanup:**

- Removed an unused import of the `os` package from
`ghttp_server_admin.go`.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-22 20:44:57 +08:00
9cc1cf1b53 fix(cmd/gf): remove dir after process done if given build file parameter is not a file but a dir name (#3908) 2024-11-11 21:32:58 +08:00
6abd8bd864 comments update for package gstr (#3233) 2024-01-02 20:16:51 +08:00
7c9eefef3d feat: Preserve original file permissions & Default copy permissions c… (#2969) 2023-09-19 20:20:13 +08:00
5219c5c37e add ut cases for command gen dao (#2958) 2023-09-12 22:00:35 +08:00
6a4e39e815 change temp dir to os.TempDir for package gfile (#2547) 2023-03-29 11:58:20 +08:00
ed0b3c039a improve package gsession; improve command docker for cli 2022-04-26 22:42:56 +08:00
eef25c28b4 improve command docker/gen service 2022-04-26 17:49:01 +08:00
12fdfbf8b2 improve package gcfg 2022-03-01 21:14:45 +08:00
5f2047d61b fix issue in configuration StdoutColorDisabled for package glog; rename TempDir to Temp for package gfile 2022-02-14 14:50:25 +08:00
48c5c1e5a8 change errors wrapped by gerror.Wrap with error stack info for all packages 2021-12-23 00:09:00 +08:00
cafd9098d7 change errors wrapped by gerror.Wrap with error stack info for all packages 2021-12-22 22:22:42 +08:00
b664982be3 [feature] improve code gfile gcfg 2021-11-15 20:26:31 +08:00
79a233eb78 example&comment update 2021-11-01 19:46:39 +08:00
fa5499373a replace char <xxx> to ;add GetWithEnv/GetWithCmd fuctions for package gcfg 2021-10-21 18:22:47 +08:00
1bc0635f8b version 2 2021-10-11 21:41:56 +08:00
6a24b595f0 upgrade otel from 0.16.0 to 0.18.0 2021-03-18 10:39:23 +08:00
093034acd1 copyright comment update 2021-01-17 21:46:25 +08:00
4991e14dff improve error message when failed in Mkdir 2021-01-03 12:05:04 +08:00
a926033b66 move Separator from const to variable for package gfile 2020-07-30 20:57:08 +08:00
8050efb835 improve package gfile 2020-05-16 14:06:35 +08:00
acc2a6a353 improve copy feature for package gfile 2020-05-16 00:50:01 +08:00
74c65439fc add function ScanDirFunc for package gfile 2020-05-15 21:51:03 +08:00
2fd5a1574a improve package gres 2020-05-14 20:32:01 +08:00
b79ff84c6f add struct slice conversion for request parameters for ghttp.Request; improve package gconv 2020-04-30 16:53:47 +08:00
b17e3a6804 improve package gset 2020-04-13 23:44:43 +08:00
f1f575fd5c improve package gins/gfile/intlog 2020-03-28 00:37:23 +08:00
ba56eb87b1 improve rotation feature for package glog 2020-03-26 20:58:57 +08:00
74be9fac18 add file rotation feature for package glog; improve gpool/gfpool; fix issue in gfile.MTimeMillisecond 2020-03-15 19:32:26 +08:00
6665d62e7e improve package gfile 2020-03-07 20:28:00 +08:00
a34ca0ff4b improve uploading file feature for ghttp.Server; improve package gfile/gstr/gdebug 2020-03-07 19:31:33 +08:00
d8a7e36478 improve router feature for ghttp.Server 2020-03-04 17:29:23 +08:00
134e4cf28f improve gfile.CopyDir function; add Model function for gdb.Model 2019-12-28 13:55:05 +08:00
80c6ceaf26 fix issue 437 2019-12-25 21:22:06 +08:00
87295ef1fe improve process communication feature for gproc; add more slice converting functions for gconv 2019-12-11 21:22:41 +08:00
0cce858641 improve configuration feature for ghttp.Server/gview/glog 2019-11-28 23:19:37 +08:00
66355354fc improve gfsnotify/gview and container 2019-10-31 23:37:33 +08:00
3218c89f17 improve gfile/gstr/ghttp 2019-09-23 16:21:19 +08:00
b39d653fe9 add package gsession; mv gkvdb to new repo 2019-09-11 21:19:45 +08:00
7f943c6b5f improving gview with i18n 2019-09-09 22:56:54 +08:00
952eb7df15 add Scan/Scanf functions for gcmd; improve gfile.IsEmpty 2019-09-05 20:00:01 +08:00
dfc76ddb76 add IsEmpty function for gfile 2019-09-05 19:22:11 +08:00
b01add2925 update project structure 2019-07-29 21:01:19 +08:00