Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve apns_utils:sing/1 in order to use os:cmd/1 instead of ktn_os:command/1 #159

Closed
cabol opened this issue Apr 13, 2017 · 0 comments
Closed
Milestone

Comments

@cabol
Copy link
Contributor

cabol commented Apr 13, 2017

NOTE: This issue is related to inaka/erlang-katana#149

As @getong points out in #157, there is a race condition that was fixed in os:cmd here.

We still need ktn_os:command because we want to find out the exit status code of the command we're running. The idea is to replace ktn_os:command/1 by os:cmd/1, but wrapping os:cmd/1 function in another one adding the necessary logic to validate if the command was executed successfully or not.

Possible solution:

-spec cmd(string()) -> {0 | 1, string()}.
cmd(Cmd) ->
  NewCmd = "
    R=$(" ++ Cmd ++ ")\n
    if [ $? -eq 0 ];then\n
      echo \"0::$R\"\n
    fi",
  case string:tokens(os:cmd(NewCmd), "::") of
    ["0", Result] -> {0, Result};
    Error         -> {1, Error}
  end.
elbrujohalcon pushed a commit that referenced this issue Apr 13, 2017
[#159] – Improve `apns_utils:sing/1` in order to use `os:cmd/1`.
@ferigis ferigis added this to the 2.1.0 milestone May 23, 2017
@cabol cabol closed this as completed May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants